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.  [ 2 posts ] 
Author Message
 Post subject: Use of sequence without creating an entity
PostPosted: Tue May 12, 2009 9:18 am 
Newbie

Joined: Sat Aug 06, 2005 1:38 am
Posts: 4
hi,
I already have created a sequence in the database.
I want to use it to fill an ID field (auto-incremented then) of a table.
I did not create an entity for that table (i have to use a specific API to insert data into that table).

How can i get that sequence in Hibernate and use it to set the value of that ID field ?
Without using an entity that maps to that table.

thanks a lot for your help.


Top
 Profile  
 
 Post subject: Re: Use of sequence without creating an entity
PostPosted: Tue May 12, 2009 10:14 am 
Newbie

Joined: Wed Jan 28, 2009 9:57 am
Posts: 16
Location: Leinfelden, Germany
Hi,
I hope i've understood your question correctly.
You can use a SQL query to query the sequence for values.
For example:
Code:
((Integer) HibernateUtil.getSession().createSQLQuery(SQL_QUERY_FOR_SEQUENCE_NEXTVAL)
                .uniqueResult()).intValue()

Since the sequence isin't (and can never be) a hibernate managed object, you cannot use other mechnism (HQL, etc) but SQL query for this.
Hope this helps!


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.