0

I'm upgrading Hibernate4 to Hibernate5. Spring-4.3.7 And facing the problem that hibernate assigns duplicate IDs to the objects while EntityManager.persist(object) that results in exception :-

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=]

I debug inside the SharedEntityManagerCreator and found that, hibernate only assigns 0 - 49 objects total 50 ids and after that it start duplicating the ids.

I'm using the sequence generator 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;
    } 

This is working fine with Hibernate4. What could be the problem here, please.

Abhishek-M
  • 410
  • 2
  • 14
  • Checkout comments and links there: https://hibernate.atlassian.net/browse/HHH-10983 – Popandopolos Jun 09 '17 at 07:11
  • Thank you @Popandopolos, it worked. :-) i added property "false" to hibernate jpaProperties, now it's using old SequenceHiLoGenerator, that actually working in my case. – Abhishek-M Jun 09 '17 at 10:38

0 Answers0