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.  [ 3 posts ] 
Author Message
 Post subject: access sequence
PostPosted: Tue May 19, 2009 12:44 pm 
Newbie

Joined: Tue May 19, 2009 12:28 pm
Posts: 2
Hi,

I have a sequence, my_seq, in a db2 database. I try to access it by means of Hibernate native sql. However, I always get the following hibernate exception.


org.hibernate.QueryException: addEntity() or addScalar() must be called on a sql query before executing the query.

As per the exception, I should add addEntity/addScalar to the sql statement. However, I don't know the right way that addEntity/addScalar should be added for a single sequence object.

I tried Query query = session.createSQLQuery(sql).addScalar( "my_seq", Hibernate.INTEGER); -- still wrong...

Any help please? Thanks!


BTW, here is the way I am using:

************************
session =sessionFactory.openSession();
String sql ="VALUES NEXTVAL for my_seq";
Query query = session.createSQLQuery(sql);
long value = ((Long) query.uniqueResult()).longValue();
************************

Thanks,
C


Top
 Profile  
 
 Post subject: Re: access sequence
PostPosted: Tue May 19, 2009 3:19 pm 
Newbie

Joined: Sat Nov 29, 2008 10:56 am
Posts: 8
set a scalar value on the query before it is executed.

.addScalar("column_name", Hibernate.LONG);


Top
 Profile  
 
 Post subject: Re: access sequence
PostPosted: Wed May 20, 2009 12:34 pm 
Newbie

Joined: Tue May 19, 2009 12:28 pm
Posts: 2
thanks!
But for a single sequence object, what's its "column_name"?


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