This content has been marked as final.
Show 2 replies
-
1. Re: Execute native SQL query
mikkus70 Dec 10, 2009 1:32 AM (in response to newlukai)Jens,
Your code is not strictly hibernate, but JPA (yes, hibernate IS providing the JPA support, but APIs are not the same and don't have the same capabilities).
Metaphisical hair-splitting aside, getSingleResult()'s name is somewhat missguiding: you're not getting a single result (intended as a single scalar value), but rather a single row of data. So, the query made by hibernate is ok, it just returns the sequence value as the sole element of a list. You can retrieve it with:
Long seqNumber = (Long)((List)em.createNativeQuery("select SEQ_PRC_CHANGE_ID.nextval from dual").getSingleResult()).get(0);
-
2. Re: Execute native SQL query
newlukai Dec 10, 2009 11:25 AM (in response to newlukai)Thanks! It works now.
I just thought getSingleResult() would do the same as (em.createNativeQuery("xxx").getResult()).get(0) ...