I've a sequence defined in my Oracle database.
Can I pull from this sequence using Hibernate? I don't want to use the sequence for generating ids for my objects, so @GeneratedValue and @Id are not the things I am looking for.
2 Answers
Something like this:
<sql-query name="sequenceValue">
<return alias="mySeq" class="MySequences"/>
select my_schema.seq_myid.nextval as mySeq from dual
</sql-query>
1 Comment
Rachel
How do we do it from hbm file?
Have you tried:
select my_schema.seq_myid.nextval from dual;
This will return a one record result set with the next value in your sequence. You can then use
select my_schema.seq_myid.currval from dual;
To get the current value of the sequence.
2 Comments
tobiasbayer
The key issue of my question is "...using Hibernate".
RC.
I understand, but I don't believe Hibernate explicitly does what you're asking to do. Therefore, you execute the query (using Hibernate) and you receive the data you're looking for.