1

我刚刚使用与 SQLite 相同的映射和源数据设置了一个 Sql Server 数据库,当我尝试保存一批测试数据时出现以下错误。

我怀疑这是 SQLite 没有捕捉到的 hilo 问题,但我无法完全理解它。我正在使用 SchemaExport 工具生成数据库,它创建了一个初始为“1”的 hibernate_unique_key 表。错误后为“2”

有什么建议么?

干杯,
贝里尔

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)
4

1 回答 1

1

问题似乎与您的 hilo 表无关。从我使用 hilo 密钥生成的经验来看,这是正确的。根据例外情况,您违反了 ActivitySubjects 的唯一键约束。检查您的唯一键约束。

于 2010-12-23T19:11:35.390 回答