Hello,
I am trying to do a SQL query on selective columns of my database Table and hence populate selective fields of my @Entity pojo (performance reason). Let's say I have an @Entity class A that has p1, p2,p3 fields and I only need p1 and p2 to be populated. In order to achieve that, I changed my @NamedQuery's query="from A a...." to query="SELECT a.p1,a.p2 from A...". It works fine except that Hibernate now returns the result as Object instead of type A subsequently throwing
Code:
java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to A"
I explored using @NamedNativeQuery instead and indicating resultClass="A.class" but as far as possible I do not want to use native sql.
Is there a way to only populate partial properties of my @Entity pojo via @NamedQuery and still get the result as my class instead of generic Object type?
Thanks