Is it good to have a duplicate generator defined in this save module?

My position is described here:

eclipse Duplicate generator named "ID_GENERATOR" defined in this persistence sequence

However, my question is different, and the selected answer does not solve it:

"Does it make sense to have several @SequenceGenerator with the same name , although it is used for this purpose by Hibernate: how to redefine an attribute from the mapped super class ?"

If not valid, is there an alternative?

Thank you very much for your response.

+6
source share
2 answers

According to Section 11.1.48 SequenceGenerator Annotation the JPA 2.1 Specification:

Name generator scope globally for storage unit (for all types of generators).

Thus, you cannot create duplicate generators.

If you try to add the following two objects:

 @Entity(name = "Post") public static class Post { @Id @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "pooled") @GenericGenerator( name = "pooled", strategy = "org.hibernate.id.enhanced.SequenceStyleGenerator", parameters = { @Parameter(name = "sequence_name", value = "sequence"), @Parameter(name = "initial_value", value = "1"), @Parameter(name = "increment_size", value = "5"), } ) private Long id; } @Entity(name = "Announcement") public static class Announcement { @Id @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "pooled") @GenericGenerator( name = "pooled", strategy = "org.hibernate.id.enhanced.SequenceStyleGenerator", parameters = { @Parameter(name = "sequence_name", value = "sequence"), @Parameter(name = "initial_value", value = "1"), @Parameter(name = "increment_size", value = "10"), } ) private Long id; } 

Hibernate will generate the following error message:

Multiple references to the database sequence [sequence] were found trying to establish conflicting values ​​for the "increment size". Found [10] and [5]

This is because the identifier generator is global, and the two sequence configurations conflict.

+2
source

I think this is true, because at the end of the day, just so, the sleep mode will display the object in a sequence that will generate an identifier when it is stored in the database. Oracle, for example, does not care which tables use this sequence because the sequence itself is an independent entity. IMO this warning (or error) makes more sense depending on the DBMS used. IMO, I would just disable the error warning in eclipse.

+1
source

All Articles