These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: @NamedQuery for Selective Columns
PostPosted: Sun May 15, 2011 9:51 am 
Newbie

Joined: Sun May 15, 2011 9:03 am
Posts: 1
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


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.