我在父 pom 中將 spring-boot-starter-parent 從 2.1.3 更新到 2.3.11。然后當我運行代碼時出現錯誤:2022-04-13 18:19:16.668 ERROR 24960 --- [main] j.LocalContainerEntityManagerFactoryBean : Failed to initialize JPA EntityManagerFactory: [PersistenceUnit: default] Unable to build Hibernate SessionFactory; 嵌套例外是 org.hibernate.MappingException:無法實體化 id 生成器 [entity-name= KeycodeAudit]
原因:org.hibernate.MappingException:物體映射中[S_AUDITID]序列的增量大小設定為[50],而關聯的資料庫序列增量大小為[1]。在 org.hibernate.id.enhanced.SequenceStyleGenerator.configure(SequenceStyleGenerator.java:261) ~[hibernate-core-5.4.31.Final.jar:5.4.31.Final] 在 org.hibernate.id.factory.internal。 DefaultIdentifierGeneratorFactory.createIdentifierGenerator(DefaultIdentifierGeneratorFactory.java:118) ~[hibernate-core-5.4.31.Final.jar:5.4.31.Final]
我是spring和maven的新手。不知道是什么原因造成的。如果我將 spring-boot-starter-parent 從 2.3.11 更改回 2.1.3。然后代碼可以再次運行。
我在 application.yml 中的 JPA 設定是 jpa: properties: hibernate.dialect: org.hibernate.dialect.Oracle10gDialect
這是由于缺少架構造成的嗎?或者是其他東西?
uj5u.com熱心網友回復:
allocationSize我認為錯誤訊息表明您在物體類中指定的序列與您的資料庫中的序列不匹配的驗證錯誤。
我不確定您如何配置物體類(通過 xml 或使用注釋),但如果您使用注釋,則應按id以下模式配置欄位:
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "<seq name in java in generator anno>")
@SequenceGenerator(name = "<seq name in java in generator anno>", sequenceName = "<seq name in db>", allocationSize = 1) // Pay attention to here
private Long oid;
請注意allocationSize輸入SequenceGenerator。如果您查看它的源代碼,您可能會發現它是可選的,因為它提供了默認值“50”。
/**
* (Optional) The amount to increment by when allocating
* sequence numbers from the sequence.
*/
int allocationSize() default 50;
此條目對應于increment by您在 Oracle 中定義序列時的情況。您應該手動將其指定為 1,這可能是問題的根本原因。
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/459058.html
