Home Negative Id values generation with GenerationType.SEQUENCE
Reply: 0

Negative Id values generation with GenerationType.SEQUENCE

user1284
1#
user1284 Published in April 24, 2018, 10:15 pm

Why do I always get negative values of an entity id? Wheter it related with increment amount value? For example while I'm using

create sequence message_sequence start 1 increment 1;

I always get negative values (-38, -44, -45). But in case I'm putting

create sequence message_sequence start 1 increment 50;

It's all fine (52, 102). Why so weird behavior? This is an entity:

@Entity
@Table(name = "messages")
public class Message {
    @Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "message_sequence")
    @SequenceGenerator(name = "message_sequence", sequenceName = "message_sequence")
    private long id;

    private String text;

    public void setText(String text) {
        this.text = text;
    }

    public String getText() {
        return text;
    }
}

programe entrance point:

EntityManagerFactory emf = JPAUtility.getEntityManagerFactory();

EntityManager entityManager = emf.createEntityManager();

entityManager.getTransaction().begin();

Message m = new Message();
m.setText("Hello World");

etityManager.persist(m);

entityManager.getTransaction().commit();
entityManager.close();
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.309873 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO