-->
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: Printing a join.
PostPosted: Fri May 28, 2004 7:55 am 
Regular
Regular

Joined: Tue May 11, 2004 9:23 am
Posts: 69
Hey,

So I've performed a select query on one table and by its association hibernate does internally a join from CustomerT to CountryT (Many-to-one in this case).

When I'm printing it I get this fault:

Code:
java.lang.ClassCastException: net.sf.hibernate.CountryT
   at net.sf.hibernate.TestCountryStore.joinCustomerorderCustomerorderlines(TestCountryStore.java:146)
   at net.sf.hibernate.TestCountryStore.menu(TestCountryStore.java:63)
   at net.sf.hibernate.TestCountryStore.main(TestCountryStore.java:212)
Exception in thread "main"


Do I have to do something special with CountryT when I iterate the result?


Best regards

Newman


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 28, 2004 7:56 am 
Regular
Regular

Joined: Tue May 11, 2004 9:23 am
Posts: 69
My source code:

Code:
Query q = session.createQuery("SELECT c.customerTPK.customerno, "
      + "c.customerTPK.countryT "
      + "FROM net.sf.hibernate.CustomerT c "
      + "WHERE c.customerTPK.customerno='1397549'");

      
      List list = q.list();
      
      System.out.println("Found " + list.size() + " matching search criteria\n");
      
      System.out.println("JOIN OF CUSTOMERORDER & CUSTOMERORDERLINES");
      System.out.println("------------------------------------------");   
                  
      for (Iterator i = list.iterator(); i.hasNext();) {
         Object[] obj = (Object[]) i.next();
         String customerno = (String) obj[0];
         String countryT = (String) obj[1];
         System.out.println(customerno);
         System.out.println(countryT);
         

      }


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 28, 2004 8:00 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
Please man, learn how to use a debugger. obj[1] is not a String but a CountryT object.


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 28, 2004 8:39 am 
Regular
Regular

Joined: Tue May 11, 2004 9:23 am
Posts: 69
I'm using debugging, but sometimes your not supposed to program a friday afternoon. =)


//Newman


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