-->
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.  [ 7 posts ] 
Author Message
 Post subject: Wrong query output using createQuery
PostPosted: Wed Jun 11, 2008 11:19 am 
Newbie

Joined: Wed Jun 11, 2008 10:40 am
Posts: 3
Hibernate version 3.2.6
Oracle 10g

Hi,

I'm trying to perform a simple

Code:
List list=session.createQuery("from MyJavaObject").list();


but Hibernate is not returning the expected results. I have the "show_sql" enabled and when I execute the SELECT sql statement that Hibernate prints to the console it shows a different resultset than the one returned by createQuery through the
Code:
list
object.

Could this be a mapping configuration problem? This is my first time using Hibernate but so far I have the same setup as all the sample codes I've found. If someone knows any possible reasons or any "must" please reply to this post.

Any help will be really appreciated! Thanks!


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 11, 2008 12:46 pm 
Expert
Expert

Joined: Tue May 13, 2008 3:42 pm
Posts: 919
Location: Toronto & Ajax Ontario www.hibernatemadeeasy.com
So, your list should be a collection of MyJavaObject types, correct? The list is holding lazy objects, that need to be cast into the appropriate type.

A list.get(0).getClass() would tell you exactly what class type the list contains. You might want to print that information to the console, assuming of course at least one record is returned. Otherwise you'll get an ArrayIndexOutOfBounds exception.

Shoot us a snippet of your Java code if you can.

_________________
Cameron McKenzie - Author of "Hibernate Made Easy" and "What is WebSphere?"
http://www.TheBookOnHibernate.com Check out my 'easy to follow' Hibernate & JPA Tutorials


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 11, 2008 1:02 pm 
Newbie

Joined: Wed Jun 11, 2008 10:40 am
Posts: 3
Hi,

The list of MyJavaObjects is being returned but the problem is that Hibernate is filling them up with incorrect data. When I execute the SELECT statement that it prints (and that it apparenlty is using to retreive the data from the database) the results I get from an external tool such as SQL*Plus and Oracle SQL Developer is not compatible with the one that I got from the result set object (list). Sorry for not being able to provide you with the code snippet.

Thanks for your help!


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 11, 2008 4:35 pm 
Newbie

Joined: Tue Apr 29, 2008 1:42 pm
Posts: 12
Does this class have an association to another class? Could you please briefly explain the differences you got in your two results?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 11, 2008 5:17 pm 
Beginner
Beginner

Joined: Tue Dec 12, 2006 6:43 am
Posts: 32
Location: London
Can you post the sql statement which get generated from Hibernate

Thank

_________________
Alan Mehio
London
UK


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 12, 2008 12:05 pm 
Newbie

Joined: Wed Jun 11, 2008 10:40 am
Posts: 3
Hi to all,

I have finally solved the problem. I had to identify that my primary key was a <composite-id> in my hbm.xml file.

Thank you all very much for your help!


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 12, 2008 4:52 pm 
Expert
Expert

Joined: Tue May 13, 2008 3:42 pm
Posts: 919
Location: Toronto & Ajax Ontario www.hibernatemadeeasy.com
Thanks for the solution!

_________________
Cameron McKenzie - Author of "Hibernate Made Easy" and "What is WebSphere?"
http://www.TheBookOnHibernate.com Check out my 'easy to follow' Hibernate & JPA Tutorials


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 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.