Reputation: 719
I have a class annotated like this:
@Entity
@Table(name="MYENTITY")
@SequenceGenerator(name="CODE_GEN", sequenceName="SEQ_NAME")
public class MyEntity {
@Id
@GeneratedValue(strategy=GenerationType.AUTO, generator="CODE_GEN")
@Column(name="CODE", nullable=false)
private int code;
I'm using hibernate 3.6.10 and Oracle10gDialect. The database is Oracle 10g. A sequence was created:
CREATE SEQUENCE SCHEMA_NAME.SEQ_NAME
START WITH 0
MAXVALUE 999999999999999999999999999
MINVALUE 0
NOCYCLE
NOCACHE
NOORDER;
COMMIT;
When I try to persist a MyEntity class, I get:
Hibernate: select hibernate_sequence.nextval from dual
19-jul-2012 13:31:24 org.hibernate.util.JDBCExceptionReporter logExceptions
WARNING: SQL Error: 2289, SQLState: 42000
19-jul-2012 13:31:24 org.hibernate.util.JDBCExceptionReporter logExceptions
GRAVE: ORA-02289: sequence not exist
Why is hibernate always trying to access hibernate_sequence if I'm declaring the sequence name with @SequenceGenerator (sequenceName="SEQ_NAME")? Is there something wrong in my annotations?
I have tried lots of combinations and Hibernate always ignores the sequence name and looks for "hibernate_sequence". BTW I'm using GenerationType.AUTO because this app must also runs vs SQLServer.
Thanks...
Upvotes: 2
Views: 2396
Reputation: 719
I finally was able to use my own sequences using hibernate's own annotation, as it seems that this version doesn't completely support the annotation @SequenceGenerator. So the code ended up like this:
@Entity
@Table(name="MYENTITY")
@GenericGenerator(name="CODE_GEN", strategy = "native", parameters =
{ @Parameter(name="sequence", value="SEQ_NAME")})
public class MyEntity {
@Id
@GeneratedValue(strategy=GenerationType.AUTO, generator="CODE_GEN")
@Column(name="CODE", nullable=false)
private int code;
Replacing @SequenceGenerator with @GenericGenerator did the trick.
Upvotes: 3
Reputation: 4022
According to the JPA spec, @SequenceGenerator can either annotate a class or a primary key field. I think it's worth a try to move it to the field and see, if that works.
Upvotes: 0