Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Hibernate- How get next value from a squence

 
M Mehta
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have a sequence in the Oracle databse. I want to get the next value of the sequence from Java code. Is it possible to do the same. What I got from search on google is only that we can create custom sequences using Hibernate.

Regards,
Me
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I want to get the next value of the sequence from Java code

Why? If you are using Hibernate with the sequence generator class you shouldn't ever need to get the value of the sequence explicitly. That is, unless you are using the sequence for something other than primary key generation?
 
M Mehta
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a column in a different table. The value of this column is to be generated by appending the value of a column from table 1 and the next val from sequence.
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok. Well I'd assume you can map the sequence as a named query. Check the docs for how to do this.
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The query text that you will want to use is

"SELECT <sequenceNameHere>.nextval from Dual"

Mark
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic