|
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
|