我使用 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 .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 網頁上的遷移指南,但找不到失敗。
uj5u.com熱心網友回復:
VALUE是 H2 中的關鍵字,并且是 SQL 標準中的保留字(即使在古老的 SQL-92 中)。用作識別符號時,需要參考為"VALUE". Hibernate ORM有一個hibernate.globally_quoted_identifiers設定,可以設定true為參考所有識別符號,可以啟用。
如果出于某種原因不想全部參考它們,可以添加;NON_KEYWORDS=VALUE到 H2 的 JDBC URL,但此設定可能不適用于所有情況。
您還需要;MODE=LEGACYHibernate ORM 5.6,因為H2Dialect會產生默認被 H2 2.x 拒絕的無效 SQL,此方言在 Hibernate ORM 6.0 版本的開發源中已修復,但尚未發布。
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/419235.html
標籤:
