0

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?

ivan
  • 307
  • 3
  • 12
  • Possible duplicate of [Hibernate generates negative id values when using a sequence](https://stackoverflow.com/questions/9861416/hibernate-generates-negative-id-values-when-using-a-sequence) – Simon Martinelli Dec 05 '18 at 15:02
  • I didn't use Jboss but even if it's the same issue I'm still really interested in knowing how the same sql shown to be used by hibernate can produce different results. – ivan Dec 07 '18 at 13:44
  • You didn't read the answer. What's the preallocation size of test_id_seq? – Simon Martinelli Dec 07 '18 at 14:17

0 Answers0