当使用@TableGenerator时,Hibernate尝试两次创建相同的实体/表-如何避免?
我将hibernate与部署在JBoss6.0上的J2EE应用程序一起使用。 我的数据库是Oracle11i和Derby。 为了生成主键(运行序列Id),我使用@TableGenerator注释 在我的一个实体(PersonDTO)中,例如: 我已经为sequence-like定义了所需的实体:当使用@TableGenerator时,Hibernate尝试两次创建相同的实体/表-如何避免?,hibernate,jpa,spring-data-jpa,entity,javabeans,Hibernate,Jpa,Spring Data Jpa,Entity,Javabeans,我将hibernate与部署在JBoss6.0上的J2EE应用程序一起使用。 我的数据库是Oracle11i和Derby。 为了生成主键(运行序列Id),我使用@TableGenerator注释 在我的一个实体(PersonDTO)中,例如: 我已经为sequence-like定义了所需的实体: @Entity @Table(name = "EDIS_SEQUENCE") public class EdmSequenceDTO { @Id private String SEQ_N
@Entity
@Table(name = "EDIS_SEQUENCE")
public class EdmSequenceDTO {
@Id
private String SEQ_NAME;
private long SEQ_COUNT;
.
.
.
就序列生成而言,一切正常。
但是在创建实体的过程中(当我第一次部署J2EE应用程序时),
我在JBoss server.log文件中看到以下错误,尽管我的所有实体/表最终都成功创建
14:04:16,817 ERROR [org.hibernate.tool.hbm2ddl.SchemaUpdate] Unsuccessful: create table EDIS_SEQUENCE ( SEQ_NAME varchar(255), SEQ_COUNT integer )
14:04:16,817 ERROR [org.hibernate.tool.hbm2ddl.SchemaUpdate] Table/View 'EDIS_SEQUENCE' already exists in Schema 'EDM'.
14:04:16,818 INFO [org.hibernate.tool.hbm2ddl.SchemaUpdate] schema update complete**
我相信这“不是”实际上是一个错误。看起来,由于我在2个实体bean中引用了EDIS\u序列
,hibernate尝试创建它两次。
首先,当部署EdmSequenceDTO时,其次当PersonDTO引用EDIS\u序列作为@TableGenerator
注释的一部分时
在我的persistence.xml
文件中,我有hibernate.hbm2ddl.auto
属性
value=“更新”。
我需要有这个值,而不是“createdrop”
我想知道是否有任何方法可以避免hibernate报告的错误?如果问题尚未解决,则不应将EDIS\u序列表映射到实体类。它由hibernate内部使用。没有人遇到此错误??呵呵!!
14:04:16,817 ERROR [org.hibernate.tool.hbm2ddl.SchemaUpdate] Unsuccessful: create table EDIS_SEQUENCE ( SEQ_NAME varchar(255), SEQ_COUNT integer )
14:04:16,817 ERROR [org.hibernate.tool.hbm2ddl.SchemaUpdate] Table/View 'EDIS_SEQUENCE' already exists in Schema 'EDM'.
14:04:16,818 INFO [org.hibernate.tool.hbm2ddl.SchemaUpdate] schema update complete**