hibernate5为对象分配重复的id

时间:2017-06-09 05:55:49

标签: java hibernate entitymanager hibernate-4.x hibernate-5.x

我正在将Hibernate4升级到Hibernate5。 Spring-4.3.7并面临hibernate为对象分配重复ID的问题,而EntityManager.persist(object)导致异常: -

org.springframework.dao.DataIntegrityViolationException: A different object with the same identifier value was
 already associated with the session : [com.domain.multilanguage.LiteralText#498]; nested exception
is javax.persistence.EntityExistsException: A different object with the same identifier value was already associated with the session : [com.domain.multilanguage.LiteralText#498][machine=]

我在SharedEntityManagerCreator中进行调试,发现hibernate只分配了0到49个对象,总共50个ID,然后开始复制id。

我正在使用序列生成器GenerationType.SEQUENCE。

    @Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "idGenerator")
    @SequenceGenerator(name = "idGenerator", sequenceName = "HIBERNATE_SEQUENCE", allocationSize = 50)
    @Column(name = "ID")
    public long getId() {
        return mId;
    } 

这适用于Hibernate4。请问这里有什么问题。

0 个答案:

没有答案