-->
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.  [ 4 posts ] 
Author Message
 Post subject: Extract single entity from criteria query result
PostPosted: Fri Jul 23, 2010 11:04 am 
Newbie

Joined: Thu Jul 22, 2010 4:25 pm
Posts: 4
Hibernate and JPA implementation.

I am using Criteria query to create dynamic query. My generated query as bellow.

select entity1.*,entity2.*,entity3.*
from
entity1 this_,
entity2 entity2_1_,
entity3 entity3_2_
where this_.column=entity2_1_.column
and entity2_1_.column=entity3_2_.column(+)
and this_.xxxxx = ?
and this_.xxxxx = ?
and this_.xxxxx = ?

Collection<entity1> xxxx = (Collection<entity1>)Criteria.list();

Getting Exception :

java.lang.ClassCastException: com.xxx.xxx..persistence.pojo.entity2E
at org.hibernate.type.ComponentType.toLoggableString(ComponentType.java:400)
at org.hibernate.pretty.MessageHelper.collectionInfoString(MessageHelper.java:307)
at org.hibernate.loader.Loader.readCollectionElement(Loader.java:1008)
at org.hibernate.loader.Loader.readCollectionElements(Loader.java:669)
at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:614)
at org.hibernate.loader.Loader.doQuery(Loader.java:724)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:259)
at org.hibernate.loader.Loader.doList(Loader.java:2228)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2125)
at org.hibernate.loader.Loader.list(Loader.java:2120)
at org.hibernate.loader.criteria.CriteriaLoader.list(CriteriaLoader.java:118)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1596)
at org.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:306)
at org.hibernate.impl.CriteriaImpl$Subcriteria.list(CriteriaImpl.java:481)

In hibernate log getting.

result row: EntityKey[com.xxx.xxx.persistence.pojo.entity2#component[column1,column2]{column1=value1, column2=value2}], EntityKey[com.xxx.xxx.persistence.pojo.entity3#component[column1,column2]{column1=value1, column2=value2}], EntityKey[com.xxx.xxx..persistence.pojo.entity1#value]


Want to extract only entity1 from result row. Any help on this......


Top
 Profile  
 
 Post subject: Re: Extract single entity from criteria query result
PostPosted: Fri Jul 23, 2010 2:39 pm 
Newbie

Joined: Wed Jun 30, 2010 9:03 am
Posts: 3
It is interesting because I am posed with the same problem, when I am using a native query and the resultset I get back is a List of Object arrays.
try as I may, I could not cast it or rebuild my Entity objects out of it.

I considered using CriteriaBuilder, but I am not so sure.

What configuration are you using, by the way?

-ilango


Top
 Profile  
 
 Post subject: Re: Extract single entity from criteria query result
PostPosted: Fri Jul 23, 2010 2:47 pm 
Newbie

Joined: Thu Jul 22, 2010 4:25 pm
Posts: 4
I am using JPA 1.1 and Hibernate 3.2. I hope gave an answer of your question.


Top
 Profile  
 
 Post subject: Re: Extract single entity from criteria query result
PostPosted: Fri Jul 23, 2010 4:24 pm 
Newbie

Joined: Wed Jun 30, 2010 9:03 am
Posts: 3
Can you post the entire stacktrace?


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

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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.