1

I am working with hibernate, and a oracle 10 db. I need to get the next sequence value from a table, and want to know how. I saw this article, and asking: is there a better way the get the value, without defining a query?

Thanks!

Community
  • 1
  • 1
Dvora
  • 1,175
  • 1
  • 16
  • 26

1 Answers1

2

No. Getting the next (nextval) or current (currval) value from a sequence is typically done using a select. Even in PLSQL, SELECT INTO is used, like this:

SELECT YourSequence.NextVal INTO :new.ID FROM DUAL;

Simple assignment like this won't work:

:new.ID := YourSeqence.NextVal;
GolezTrol
  • 114,394
  • 18
  • 182
  • 210
  • So there is no way of doing this in hibernate? – Rachel Jul 03 '12 at 15:26
  • I have question here if you have some inputs then it would be really helpful...http://stackoverflow.com/q/11313854/164299 – Rachel Jul 03 '12 at 15:27
  • Sounds like the same question, isn't it? – GolezTrol Jul 03 '12 at 15:29
  • Yes but is there a way to do this in `hbm` file? – Rachel Jul 03 '12 at 15:30
  • @GolezTrol can you explain this http://docs.jboss.org/hibernate/core/3.6/reference/en-US/html_single/#mapping-declaration-id and what are those annotations for? I thought that was an alternative – H.Rabiee Nov 16 '15 at 11:04
  • Maybe [this question](http://stackoverflow.com/questions/5346147/hibernate-oracle-sequence-produces-large-gap) is useful. It's not exactly the same, but the question and answers show how to use sequences with hibernate. I can't help you further. I don't use hibernate in my daily work, and this questions was asked almost 5 years ago. – GolezTrol Nov 16 '15 at 11:11