Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Replace @SequenceGenerator since its deprecated

I have a problem with @SequenceGenerator:

@SequenceGenerator(name="pk_user_id", sequenceName="seq_user_id", allocationSize=1)
@GeneratedValue(strategy=GenerationType.SEQUENCE, generator="pk_user_id")

When the application starts up it shows warning:

WARN 7388 --- [ main] org.hibernate.orm.deprecation : HHH90000014: Found use of deprecated [org.hibernate.id.SequenceHiLoGenerator] sequence-based id generator; use org.hibernate.id.enhanced.SequenceStyleGenerator instead. See Hibernate Domain Model Mapping Guide for details

I tried to find out how I can replace a deprecated code with a new one but can't find any solution.

like image 559
Finchsize Avatar asked Oct 04 '16 20:10

Finchsize


People also ask

How would you implement a custom sequence based id generator?

If you want to use a custom generator, you need to define the generator in a @GenericGenerator annotation and provide the fully-qualified classname as the strategy. You can also configure a set of parameters that will be provided to the configure method when Hibernate instantiates the generator.

What is hibernate ID New_generator_mappings?

id. new_generator_mappings that directs how identity or sequence columns are generated when using @GeneratedValue . In JBoss EAP 6, the default value for this property is set as follows: When you deploy a native Hibernate application, the default value is false .

What is@ SequenceGenerator?

by. The SequenceGenerator annotation defines a primary key generator that may be referenced by name when a generator element is specified for the GeneratedValue annotation. A sequence generator may be specified on the entity class or on the primary key field or property.


1 Answers

According to the warning message and Hibernate documentation (Hibernate deprecated list) you should use SequenceStyleGenerator. Or better use @GenericGenerator and specify generator strategy.

Here is a typical example of usage:
@GenericGenerator(
        name = "wikiSequenceGenerator",
        strategy = "org.hibernate.id.enhanced.SequenceStyleGenerator",
        parameters = {
                @Parameter(name = "sequence_name", value = "WIKI_SEQUENCE"),
                @Parameter(name = "initial_value", value = "1000"),
                @Parameter(name = "increment_size", value = "1")
        }
)
@Id
@GeneratedValue(generator = "wikiSequenceGenerator")
like image 91
semenchikus Avatar answered Oct 21 '22 04:10

semenchikus