【发布时间】:2022-01-22 09:32:47
【问题描述】:
我使用 H2 内存数据库进行集成测试,而不是使用 Oracle 进行实时系统。 在我更新到新的主要 H2 版本 2 后,测试会抛出如下异常:
SQL 语句中的语法错误“select test0_.ID as id1_1_3_, test0_.TEST_ID as test_2_1_3_, test0_.PU_ID as pu8_1_3_, testpar1_.TEST_ID as test_4_2_5_, testpar1_.ID as id1_2_5_, testpar1_.ID as id1_2_0_, testpar1_.TEST_ID as test_4_2_0_, testpar1_.NAME as name2_2_0_, testpar1_.[*]VALUE as value3_2_0_, from testschema.TEST test0_ left outer join testschema.PU pu2_ on test0_.PU_ID=pu2_.ID where test0_.ID=?";预期的“标识符”;
这是一个示例实体:
@Entity
@Table(name = "TEST")
@SequenceGenerator(name = "TEST_SEQUENCE_GENERATOR",
sequenceName = "TEST_SEQ",
allocationSize = 1)
public class Test {
@Id
@Column(name = "ID")
@GeneratedValue(generator = "TEST_SEQUENCE_GENERATOR", strategy = GenerationType.SEQUENCE)
private Long id;
这些是设置属性:
properties.put("javax.persistence.jdbc.driver", "org.h2.Driver");
properties.put(
"javax.persistence.jdbc.url",
"jdbc:h2:mem:testschema;DB_CLOSE_ON_EXIT=FALSE;INIT=CREATE SCHEMA IF NOT EXISTS TESTSCHEMA");
properties.put("javax.persistence.jdbc.user", "testschema");
properties.put("javax.persistence.jdbc.password", "");
properties.put("hibernate.default_schema", "testschema");
properties.put("hibernate.show_sql", "false");
properties.put(
"hibernate.cache.region.factory_class",
"org.hibernate.cache.ehcache.SingletonEhCacheRegionFactory");
properties.put("hibernate.hbm2ddl.auto", "create-drop");
properties.put("hibernate.order_by.default_null_ordering", "last");
properties.put("hibernate.dialect", "org.hibernate.dialect.H2Dialect");
我查看了H2网页上的迁移指南,但找不到失败。
【问题讨论】:
-
使用 Hibernate ORM 5.x(由于
H2Dialect的错误)通常需要将;MODE=LEGACY添加到 H2 2.x 的 JDBC URL,但您可能还需要其他设置。请在您的问题中包含完整的例外,因为实际的错误位置隐藏在...后面。 -
感谢您的快速评论,我测试了 MODE=LEGACY 但您说得对,这还不够。