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.