Skip to main content
added 460 characters in body
Source Link
gavenkoa
  • 49.7k
  • 28
  • 274
  • 341

We import data to DB by external process and also allow to modify/add data inside app. To avoid UUIDs and simplify code single Oracle DB sequence HIBERNATE_SEQUENCE is used in external process and I need to use it for affected entities.

My naive definitions on each entity are failed:

@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "HIBERNATE_SEQUENCE") @SequenceGenerator(name = "HIBERNATE_SEQUENCE", sequenceName = "HIBERNATE_SEQUENCE") 

with:

HibernateException: Multiple references to database sequence [hibernate_sequence] were encountered attempting toset conflicting values for 'increment size'. 

HibernateException: Multiple references to database sequence [hibernate_sequence] were encountered attempting toset conflicting values for 'increment size'.

Defining only on singe entity:

@SequenceGenerator(name = "HIBERNATE_SEQUENCE", sequenceName = "HIBERNATE_SEQUENCE") 

(and @GeneratedValue on others) causes:

org.hibernate.AnnotationException: Unknown Id.generator: HIBERNATE_SEQUENCE 

org.hibernate.AnnotationException: Unknown Id.generator: HIBERNATE_SEQUENCE

How I can use single sequence on different entities?

UPDATE Also I had:

org.hibernate.HibernateException: Multiple references to database sequence [hibernate_sequence] were encountered attempting toset conflicting values for 'increment size'. Found [1] and [50]

at some stage as previously I defined physical sequence as:

create sequence HIBERNATE_SEQUENCE minvalue 1 maxvalue 9999999999999999999999999999 start with 1 increment by 1; 

and default hibernate step is 50...

We import data to DB by external process and also allow to modify/add data inside app. To avoid UUIDs and simplify code single Oracle DB sequence HIBERNATE_SEQUENCE is used in external process and I need to use it for affected entities.

My naive definitions on each entity are failed:

@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "HIBERNATE_SEQUENCE") @SequenceGenerator(name = "HIBERNATE_SEQUENCE", sequenceName = "HIBERNATE_SEQUENCE") 

with:

HibernateException: Multiple references to database sequence [hibernate_sequence] were encountered attempting toset conflicting values for 'increment size'. 

Defining only on singe entity:

@SequenceGenerator(name = "HIBERNATE_SEQUENCE", sequenceName = "HIBERNATE_SEQUENCE") 

(and @GeneratedValue on others) causes:

org.hibernate.AnnotationException: Unknown Id.generator: HIBERNATE_SEQUENCE 

How I can use single sequence on different entities?

We import data to DB by external process and also allow to modify/add data inside app. To avoid UUIDs and simplify code single Oracle DB sequence HIBERNATE_SEQUENCE is used in external process and I need to use it for affected entities.

My naive definitions on each entity are failed:

@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "HIBERNATE_SEQUENCE") @SequenceGenerator(name = "HIBERNATE_SEQUENCE", sequenceName = "HIBERNATE_SEQUENCE") 

with:

HibernateException: Multiple references to database sequence [hibernate_sequence] were encountered attempting toset conflicting values for 'increment size'.

Defining only on singe entity:

@SequenceGenerator(name = "HIBERNATE_SEQUENCE", sequenceName = "HIBERNATE_SEQUENCE") 

(and @GeneratedValue on others) causes:

org.hibernate.AnnotationException: Unknown Id.generator: HIBERNATE_SEQUENCE

How I can use single sequence on different entities?

UPDATE Also I had:

org.hibernate.HibernateException: Multiple references to database sequence [hibernate_sequence] were encountered attempting toset conflicting values for 'increment size'. Found [1] and [50]

at some stage as previously I defined physical sequence as:

create sequence HIBERNATE_SEQUENCE minvalue 1 maxvalue 9999999999999999999999999999 start with 1 increment by 1; 

and default hibernate step is 50...

edited tags; edited tags
Link
tadman
  • 212.4k
  • 23
  • 237
  • 266
Source Link
gavenkoa
  • 49.7k
  • 28
  • 274
  • 341

How to define shared sequence generator in Hibernate / JPA?

We import data to DB by external process and also allow to modify/add data inside app. To avoid UUIDs and simplify code single Oracle DB sequence HIBERNATE_SEQUENCE is used in external process and I need to use it for affected entities.

My naive definitions on each entity are failed:

@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "HIBERNATE_SEQUENCE") @SequenceGenerator(name = "HIBERNATE_SEQUENCE", sequenceName = "HIBERNATE_SEQUENCE") 

with:

HibernateException: Multiple references to database sequence [hibernate_sequence] were encountered attempting toset conflicting values for 'increment size'. 

Defining only on singe entity:

@SequenceGenerator(name = "HIBERNATE_SEQUENCE", sequenceName = "HIBERNATE_SEQUENCE") 

(and @GeneratedValue on others) causes:

org.hibernate.AnnotationException: Unknown Id.generator: HIBERNATE_SEQUENCE 

How I can use single sequence on different entities?