I have just setup a Sql Server db using the same mappings and source data that have been working with SQLite, and getting the error below when I try to save a batch of test data.
I suspect it is a hilo issue that SQLite doesn't catch but I can't quite get my brain onto it. I am using the SchemaExport tool to generate the database, which creates a hibernate_unique_key table that is initially '1'. After the error it is '2'
Any suggestions?
Cheers,
Berryl
insert into hibernate_unique_key values ( 1 )
insert into hibernate_unique_key values ( 1 )
NHibernate: SELECT this_.ActivitySubjectId as Activity1_3_0_, this_.Description as Descript3_3_0_,
this_.BusinessId as BusinessId3_0_, this_.ProjectCode as ProjectC6_3_0_ FROM ActivitySubjects this_ WHERE this_.ActivitySubjectType='PROJECT'
NHibernate: select next_hi from hibernate_unique_key with (updlock, rowlock)
NHibernate: update hibernate_unique_key set next_hi = @p0 where next_hi = @p1;@p0 = 2 [Type: Int32 (0)], @p1 = 1 [Type: Int32 (0)]
NHibernate: INSERT INTO ActivitySubjects (Description, BusinessId, ProjectCode, ActivitySubjectType, ActivitySubjectId)
VALUES (@p0, @p1, @p2, 'PROJECT', @p3);@p0 = 'Refinish Casino Chairs' [Type: String (75)], @p1 = '006-00-023' [
Type: String (25)], @p2 = '006-00-023' [Type: String (4000)], @p3 = 32768 [Type: Int32 (0)]
NHibernate: INSERT INTO ActivitySubjects (Description, BusinessId, ProjectCode, ActivitySubjectType,
ActivitySubjectId) VALUES (@p0, @p1, @p2, 'PROJECT', @p3);@p0 = 'Villa Garden Wall Enhancement'
[Type: String (75)], @p1 = '006-00-024' [Type: String (25)], @p2 = '006-00-024' [Type: String (4000)], @p3 = 32769 [Type: Int32 (0)]
Test 'M:Smack.ConstructionAdmin.Data.Tests.DbConfiguration.TestData.SqlServerDataGenerator.CreateTestDataFile' failed: could not insert:
[Smack.ConstructionAdmin.Domain.Activities.Subjects.Projects.Project#32769][SQL: INSERT INTO ActivitySubjects
(Description, BusinessId, ProjectCode, ActivitySubjectType, ActivitySubjectId) VALUES (?, ?, ?, 'PROJECT', ?)]
NHibernate.Exceptions.GenericADOException: could not insert:
[Smack.ConstructionAdmin.Domain.Activities.Subjects.Projects.Project#32769]
[SQL: INSERT INTO ActivitySubjects (Description, BusinessId, ProjectCode, ActivitySubjectType,
ActivitySubjectId) VALUES (?, ?, ?, 'PROJECT', ?)]
---> System.Data.SqlClient.SqlException: Violation of UNIQUE KEY constraint
'UQ__ActivitySubjects__49555023'. Cannot insert duplicate key in object 'dbo.ActivitySubjects'.
The statement has been terminated.
at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection)
The problem doesn't appear to be with your hilo table. That is behaving correctly from my experience using hilo key generation. According to the exception, you're violating a unique key constraint for ActivitySubjects. Check your unique key constraints.