The environment:
Database - Oracle 12c
Hibernate - 5.2.10Final
JPA - version 2.0
We are using entityManager.merge to insert the object. The value of the sequence is a positive value but when inserted in db, it becomes negative. Can't seem to find the cause of this.
Here is the hibernate setting we have for our entity object id attribute field, with the sequence setting
@Id
@SequenceGenerator(name = "someSequence", sequenceName = "SOME_SEQUENCE")
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "someSequence")
@Column(name = "RECORD_ID", unique = true, nullable = false, precision = 10, scale = 0)
private String recordId;
anyone can help? thanks.
In
SequenceGenerator
annotation there is a variable namedallocationSize
. This size is by default is50
. It means that Hibernate will reserve 50 ids and it will not need to retrieve new id for every insert. So you need:allocationSize
to the same value like in yoursomeSequence
incrementBy value.someSequence
to matchallocationSize
value.Then you problems will gone.