1

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 2

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> 
Sign up to request clarification or add additional context in comments.

1 Comment

How do we do it from hbm file?
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.

2 Comments

The key issue of my question is "...using Hibernate".
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.