creating sequence using @SequenceGenerator

1.7k views Asked by At

I would like to know if there is a way to define sequence generator java side. Generally we have sequence generators defined in database and we map them to entities using

@SequenceGenerator(name = "generator", sequenceName = "SEQ_FOO_ID"). But is there any way that hibernate itself generates the values instead of using sequence generators from database?

Thanks!

1

There are 1 answers

0
JB Nizet On BEST ANSWER

Yes, use a custom generator. The list is available in the Hibernate documentation. Some of them don't use the database: increment, and uuid*.

If you want a sequence number, the increment generator can be used, but it's very limited, because it's unusable if you have a cluster, or if any other process also inserts rows in the database.