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.
Asked
Active
Viewed 1,220 times
1

tobiasbayer
- 10,269
- 4
- 46
- 64
2 Answers
2
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.

RC.
- 27,409
- 9
- 73
- 93
-
The key issue of my question is "...using Hibernate". – tobiasbayer Dec 13 '10 at 13:46
-
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. – RC. Dec 13 '10 at 14:12
2
Something like this:
<sql-query name="sequenceValue">
<return alias="mySeq" class="MySequences"/>
select my_schema.seq_myid.nextval as mySeq from dual
</sql-query>

HamoriZ
- 2,370
- 18
- 38