我有一个使用Hibernate框架的实体,其中一个ID已经被配置为:
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
private Long id;
第一次创建新元素时,一切正常。但是如果我重新启动我的应用程序并检索回记录,下一次我尝试持久化此实体时,Hibernate 将尝试使用在应用程序未重新启动时生成的相同 ID。我遇到了下面的错误,并且在使用跟踪选项运行时,我能够看到 ID 被重用:*Hibernate: insert into org_myEntity (entitiyJID, entitityName, id) values (?, ?, ?) org.hibernate.util.JDBCExceptionReporter SQL Error: 20000, SQLState: 23505 org.hibernate.util.JDBCExceptionReporter The statement was aborted because it would have caused a duplicate key value in a unique or primary key constraint or unique index identified by 'SQL120725164357680' defined on 'TABLE_NAME'. org.hibernate.event.def.AbstractFlushingEventListener Could not synchronize database state with session org.hibernate.exception.ConstraintViolationException: could not
顺便说一句,我正在使用 Hibernate 3.3.2.GA、javax.persistence 2.0.0 和 Derby 10.5.1 数据库。有人知道我的生成有什么问题以及我该如何解决吗?