-->
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.  [ 3 posts ] 
Author Message
 Post subject: ClassCastException when using join
PostPosted: Thu Feb 16, 2006 10:04 pm 
Regular
Regular

Joined: Mon Aug 02, 2004 9:33 am
Posts: 69
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:3.1.1

Name and version of the database you are using:MySql 5.0

Hi guys,

My query is like below:

Code:
        <query name="findPostingDetailsByCategoryAndCity"><![CDATA[
            from PostingDetails as pid left join pid.lessorAddress as addr right join pid.categorizedItems as ci where addr.city = ? and ci.id.categoryId = ?
        ]]></query>


and my class is like below:

Code:
public abstract class PostingDetails implements Serializable{
   private Set lessorAddress = new HashSet();
   private Set categorizedItems = new HashSet();
}


In the DAO implementation,

Code:
   public List findPostingDetails(Long categoryId, String city){
      List list = getHibernateTemplate().findByNamedQuery(
            "findPostingDetailsByCategoryAndCity",
            new Object[] { city , categoryId });

      if (list.size() < 1)
         return null;

      return list;
   }


In my unit test:

public void testGetPosting(){
List <PostingDetails> list = postMgr.findPostingDetails(new Long(8574),"Houghton");

for(PostingDetails element : list){
System.out.println("title = "+element.getTitle());
}
}

and I got java.lang.ClassCastException. It shouldn't be class cast exception as I am querying the main class (PostingDetails). Pls help, Thanks !


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 20, 2006 10:42 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
It'd be easier to help if you'd posted the exception, but I think I know what the problem is, this time. Add a "select pid" to the beginning of your query. The query you've provided will be returning a list of Object[3]s, each one containing a PostingDetails, a LessorAddress and a CategorizedItem.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 27, 2006 6:03 am 
Regular
Regular

Joined: Mon Aug 02, 2004 9:33 am
Posts: 69
thanks a lot man !


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.