I have an entity mapped and I want to verbosely point it to its sequence. So I have the following mapping:
@Entity
@Table(schema = DbConstants.SCHEMA_PUBLIC, name =
DbConstants.PUBLIC_TABLE_TEST)
public class TestEntity implements Serializable {
private static final long serialVersionUID = 6284010266557287786L;
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "test")
@SequenceGenerator(schema = DbConstants.SCHEMA_PUBLIC, name = "test", sequenceName = "test_id_seq")
private Integer id;
}
The problem is that if I don't include allocationSize in the @SequenceGenerator annotation the entities seem to have an id of something along the lines of -49 + nextval('test_id_seq'::regclass). Adding a new entity also increments the test_id_seq. I've compared the sql that hibernate uses with or without the allocationSize and it's exactly the same.
1) How does this happen?
2) How do the database ids end up being so different with seemingly the same sql being used by hibernate?