Hello,
First time Hibernate user having trouble getting sequences working.
I use annotations to configure my POJOs, and here is an example of a place I specify my sequence:
Code:
@SequenceGenerator(name = "generator", sequenceName = "ADDR_SEQ")
@Id
@GeneratedValue(strategy = SEQUENCE, generator = "generator")
@Column(name = "ADDR_ID", nullable = false, precision = 18, scale = 0)
public Long getAddrId() {
return this.addrId;
}
I can see in my debug output that Hibernate actually does a call to this sequence, and I have had an issue where it threw an Oracle error because I initially forgot to create the sequence specified, and the error went away after I created it.
Code:
Hibernate:
select
ADDR_SEQ.nextval
from
dual
However, it seems Hibernate is not even using the sequence number it selects, because I am seeing it use numbers such as:
Quote:
4296500, 4296550, 4296600, 4296650
Those are exactly the last 4 records I inserted.
Meanwhile, if I do this:
Code:
select addr_seq.nextval from dual
I get the result:
Quote:
85934
So something is definitely wrong! I just dont know what it is....
What am I missing?
I specified my hibernate with following properties:
Code:
hibernate.dialect=org.hibernate.dialect.Oracle10gDialect
hibernate.show_sql=true
hibernate.format_sql=true
hibernate.transaction.factory=org.hibernate.transaction.JDBCTransactionFactory
The database is setup from a JNDI datasource.
When trying to research this issue I came across some talk about a entityManager in Spring config files and I thought oh maybe I need to add that but then it started to get confusing so I need to ask do I really need to do that? In my Hibernate book it didnt mention anything like that....
I got to the point where it complained about a missing persistence.xml file and when I tried creating some from examples I am finding I'd have to repeat properties I set on Hibernate in here such as dialect and datasource so I really feel like it might be going down the wrong path.