I use a Hibernate result transformer to get a list of results from a database as follows:
Query query = em.createNativeQuery("SELECT 1 as myTrueBoolean, 2 as myInt") query.unwrap(org.hibernate.Query.class).setResultTransformer(Transformers.aliasToBean(myDataClass)); query.fetchResultList()
Than I could define a data class as follows:
class MyDataClass { boolean myTrueBoolean; int myInt; }
The problem is that the transformer will not display the data correctly, as it will assign BigInteger as boolean ( IllegalArgumentException occurred while calling setter for property [MyDataClass.myTrueBoolean (expected type = boolean)]; target = MyDataClass, property value = [0]] ), and the same with the appointment of BigInteger as int. This will not be a problem for shared Hibernate objects.
EDIT:
I am not looking for an explanation why this does not work. I am looking for a way to make it work :-) I need this for my native queries. Is there a way to implement my own transformer that would do this?
source share