-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 
Author Message
 Post subject: Getting the next sequence number
PostPosted: Thu Feb 15, 2007 6:02 am 
Newbie

Joined: Mon Jan 09, 2006 8:17 am
Posts: 19
hi,

How can i get the next sequence number from a table ?

In Java API (JPA), there is something like that:

Long nextId = (Long) em.createNativeQuery("select nextval('user_id_seq'").getSingleResult();

I need the equivalent in Hibernate.

Thanks for helping.

Hibernate version: 3.1

regards
tony


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 15, 2007 6:14 am 
Newbie

Joined: Thu Feb 15, 2007 5:46 am
Posts: 12
Location: Helsinki
You can use Session.createSQLQuery() to do native SQL.

-Jussi


Top
 Profile  
 
 Post subject: Getting the next sequence number
PostPosted: Thu Feb 15, 2007 6:56 am 
Newbie

Joined: Mon Jan 09, 2006 8:17 am
Posts: 19
Kayaman wrote:
You can use Session.createSQLQuery() to do native SQL.

-Jussi


how do i do it ? it needs to be database independent ...


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 15, 2007 7:14 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
you are using something db specific so very hard to make it independent.

you will need to create the query string per db and then select the right one at runtime.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject: Getting the next sequence number
PostPosted: Thu Feb 15, 2007 7:27 am 
Newbie

Joined: Mon Jan 09, 2006 8:17 am
Posts: 19
max wrote:
you are using something db specific so very hard to make it independent.

you will need to create the query string per db and then select the right one at runtime.


ok. thanks. looks like i will need a file that serves the sequence #.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.