I have a Database StoredProcedure, which is result of multiple joins of different tables, which are not mapped as an entity . is their a way to map the result to a Pojo without declaring as an entity.
Thanks in Advance
I have a Database StoredProcedure, which is result of multiple joins of different tables, which are not mapped as an entity . is their a way to map the result to a Pojo without declaring as an entity.
Thanks in Advance
You can use a DTO projection to map the ResultSet
to a POJO.
@vlad,You mean to say something like this below
entityManager.unwrap(Query.class).setResultTransformer(Transformers.aliasToBean(Target.class));
Thanks
Yes, you can try it like that. Or, use the constructor result approach.
I have tried that way,as mentioned below but i am getting below Exception
entityManager.createNativeQuery("call my_Storedprocedure(?)").setParameter(1,myParam).unwrap(Query.class).setResultTransformer(Transformers.aliasToBean(MyTargetClass.class));
Exception
java.lang.ClassCastException: MyTargetClass cannot be cast to java.util.Map
Try to debug it and see why you get that exception.