H2数据库不尊重约束规则

时间:2016-04-19 15:23:19

标签: java sql-server-2008 junit spring-boot h2

我已进入我的spring-boot项目2数据库 - MS SQL Server用于应用程序本身,H2用于集成测试。 schema.sql的{​​{1}}文件与H2数据库的创建脚本相同,并且包含一个约束,该约束表示必须只设置两个属性中的一个。我的单元测试与SQL Server一起运行正常,但SQL Server的行为与预期不符。 H2已设置。这个测试应该失败,但它会成功完成。

MODE=MSSQLServer

sql脚本中的约束是:

@Test
public void testDatabaseConstraints() {

    ConversationThread corruptedConversationThread = new ConversationThread();
    corruptedConversationThread.setConversationThreadId(new ConversationThreadId("corruptedConversationThread"));
    corruptedConversationThread.setThreadCategory(threadCategory);

    // only family or familyMember can be set, not both at the same time
    corruptedConversationThread.setFamily(family);
    corruptedConversationThread.setFamilyMember(familyMember);

    conversationThreadRepository.save(corruptedConversationThread);
}

有人有任何想法,如何强制CREATE TABLE conversationthread ( id VARCHAR (255) NOT NULL , family_number INTEGER , familyMember_number INTEGER , thread_category_id VARCHAR (255) NOT NULL , CONSTRAINT conversationThread_PK PRIMARY KEY CLUSTERED (id) WITH ( ALLOW_PAGE_LOCKS = ON , ALLOW_ROW_LOCKS = ON ) ON "default" ) ON "default" GO ALTER TABLE conversationthread ADD CONSTRAINT check_only_one_column_is_null CHECK ( (CASE WHEN family_number IS NOT NULL THEN 1 ELSE 0 END + CASE WHEN familyMember_number IS NOT NULL THEN 1 ELSE 0 END) = 1 ) GO 数据库使这个约束起作用,这会导致测试失败,我发布了吗?

0 个答案:

没有答案