Reputation: 581
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.
Upvotes: 2
Views: 1786
Reputation: 2152
In SequenceGenerator
annotation there is a variable named allocationSize
. This size is by default is 50
. 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 your someSequence
incrementBy value.someSequence
to match allocationSize
value.Then you problems will gone.
Upvotes: 5