I am using Hibernate with Spring and DB2. I am using sequences to generate primary key for entities. All entities use the same sequence HIBERNATE_SEQUENCE
, which is the hibernate default.
The problem is that values that end up into primary keys are about 10 times higher than those returned by the HIBERNATE_SEQUENCE.
For example this situation just after a new row is inserted to tbl:
select max(id) as primary_key, nextval for hibernate_sequence sequence_value from tbl ;
primary_key sequence_value
501483661 50148373
I have mapped primary key like this, in super class for all entities:
@MappedSuperclass
public class AbstractEntity implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE)
private Integer id;
I'd like that hibernate uses those values it fetches from the sequence, not sequence values multiplied by 10. What is the correct way to do this?