我在 hibernate 中编写了一些代码。在这段代码中,我想将集合作为新表插入数据库中,此代码创建表并映射外键
,但无法在表中插入数据并抛出异常。
这是我的 hibernate 代码:
@ElementCollection()
@JoinTable(name="user_address",
joinColumns=@JoinColumn(name="userId")
)
@GenericGenerator(name = "hilo-gen", strategy ="hilo")
@CollectionId(columns = { @Column(name="address_id") }, generator ="hilo-gen", type =@Type(type="long"))
这是一些错误:
org.hibernate.internal.SessionImpl$5 mapManagedFlushFailure
ERROR: HHH000346: Error during managed flush [org.hibernate.id.IdentifierGeneratorHelper$2 cannot be cast to java.lang.Long]
Exception in thread "main" java.lang.ClassCastException: org.hibernate.id.IdentifierGeneratorHelper$2 cannot be cast to java.lang.Long
最佳答案
尝试使用不同的生成器策略。
@GenericGenerator(name = "inc-gen", Strategy ="increment")
应该可以正常工作。
关于java - Hibernate @CollectionId 有错误 : HHH000346: Error during managed flush,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32595527/