JPA hibernate with sequence stratery as legacy_hilo and multiple applications deployed

185 views Asked by At

I'm using JPA with hibernate and have a bean defined like this.

@Entity
@Table(name = "ARTICLE")
@GenericGenerator(
        name = "ARTICLE_GEN",
        strategy = "sequence",
        parameters = {
                @Parameter(name = "sequence_name", value = "ARTICLE_SEQ"),
                @Parameter(name = "increment_size", value = "400"),
                @Parameter(name = "optimizer", value = "legacy-hilo")
})

multiple applications use the same entity and are pointing the same database.

The problem is that from time to time, I'm getting at one of the applications this error:

oracle.jdbc.OracleDatabaseException: ORA-00001: unique constraint (ARTICLE.PK_2) violated

I'm pretty sure one of the applications is walking into the other application sequence cache. I'm searching for best practices to manage sequence cache with many applications context, or any subgestion to improve the mapping.

Regards,

2

There are 2 answers

0
Christian Beikov On

I think you have to annotate @javax.persistence.SequenceGenerator(allocationSize = 400) so that Hibernate knows it should increment by 400.

0
Fozix On

Thanks Christian for your Answer.

We figure it out, it was an application not sharing the same increment size. So we found ourseft with duplicate keys insert.