Native Query issues [message #385295] |
Sat, 24 January 2009 09:13 |
Ari Meyer Messages: 136 Registered: July 2009 |
Senior Member |
|
|
Hi,
I'm using EclipseLink 1.0.2, and I need to hit an Oracle 10.2 sequence
in ad hoc fashion (NOT when inserting a record), so I created a native
query like so (snippet):
final String query =
"SELECT proj_num_seq.nextval " +
"FROM dual ";
return (Long) _entityManager
.createNativeQuery(query)
.getSingleResult();
When this was executed, I got this bizarre error:
java.lang.ClassCastException:
org.eclipse.persistence.internal.helper.NonSynchronizedVecto r
So I see that it's returning a List, not the "single result" I
requested. Bug?
I then tried this:
List aList = (List) _entityManager
.createNativeQuery(query)
.getSingleResult();
return (Long) aList.get(0);
.... which resulted in:
java.lang.ClassCastException: java.math.BigDecimal
Finally, I ended up having to do this:
List aList = (List) _entityManager
.createNativeQuery(query)
.getSingleResult();
return ((BigDecimal) aList.get(0)).longValue();
or this with generics:
List<BigDecimal> aList = (List<BigDecimal>)
_entityManager.createNativeQuery(query)
.getSingleResult();
return aList.get(0).longValue();
All good now!
But the first attempt should have worked correctly, right? It should
not have returned a List holding a BigDecimal (maybe just a BigDecimal
for me to deal with, which at least would have been somewhat
acceptable). Also, just for fun, when I tried it with getResultList()
instead of getSingleResult(), it wrapped the List in another List, which
is what I expected.
So is createNativeQuery(String).getSingleResult() misbehaving, or am I
doing something wrong? I didn't find any similar bug reports or news
postings.
Thanks,
Ari
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.04764 seconds