I'm working on switching my JPA persistence provider from EclipseLink 2.3 to Hibernate 3.6.5.Final. The problem is with a native query. Note: this wasn't a problem with EclipseLink. I'm trying to obtain a scalar value, a String
from a table that I don't have an Entity declared for. Here is the code:
Query q = em.createNativeQuery("select description from foo where foo_id = ?");
q.setParameter(1, fooId);
String description = (String)q.getSingleResult();
With Hibernate I get a ClassCastException
because the object returned is actually a proxy object. I don't know what type it is, but I know it isn't an array (object.getClass().isArray()
is false) and I know it isn't a List (object instanceof List
is false
).
What am I missing?
Summarizing comments below the question:
What interfaces does
q.getSingleResult().getClass().getInterfaces()
return?
It is of type
java.sql.Clob
,org.hibernate.engine.jdbc.WrappedClob
, andjava.io.Serializable
. [...] I didn't even realize the column was a clob and I'm surprised EclipseLink was doing the conversion to String for me
Looks like EclipseLink is smart enough to convert CLOB (which is actually a very long sequence of characters, just like String
) to String
if required. With Hibernate this must be done explicitly. I guess this complies to the JPA specification.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With