Hibernate: How to use a comment to specify a custom sequence generator class name?

I want to use comments to specify the following hbm configuration:



I don’t know how to provide the class name< /p>

@GeneratedValue(strategy=GenerationType.SEQUENCE, generator="SEQ_STORE")

Do I have to specify @ javax.persistence in each entity class. SequenceGenerator?
Can I specify only the class name under the @GeneratedValue annotation?

Please find the following code set I used in the project.

< p>

@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "XyzIdGenerator")
@GenericGenerator(name = "XyzIdGenerator",
strategy = " com.mycompany.myapp.id.BigIntegerSequenceGenerator",
parameters = {
@Parameter(name = "sequence", value = "xyz_id_sequence")
})
public BigInteger getId ()
{
return id;
}


package com.mycompany.myapp.id;

import org .hibernate.id.SequenceGenerator;
...

public class BigIntegerSequenceGenerator
extends SequenceGenerator
{
@Override
public Serializable generate( SessionImplementor session, Object obj)
{
...
}
}

I want to use comments to specify the following hbm Configuration:



I don’t know how to provide the class name

 @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="SEQ_STORE")

Do I have to specify @ javax.persistence.SequenceGenerator in each entity class?
Can I specify only the class name under the @GeneratedValue annotation?

Please find the following code set I used in the project.

@Id< br />@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "XyzIdGenerator")
@GenericGenerator(name = "XyzIdGenerator",
strategy = "com.mycompany.myapp.id.BigIntegerSequenceGenerator",< br /> parameters = {
@Parameter(name = "sequence", value = "xyz_id_sequence")
})
public BigInteger getId()
{
return id;
}


package com.mycompany.myapp.id;

import org.hibernate.id.SequenceGenerator;
. ..

public class BigIntegerSequenceGenerator
extends SequenceGenerator
{
@Override
public Serializable generate(SessionImplementor session, Object obj)
{< br /> ...
}
}

Leave a Comment

Your email address will not be published.