-->
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.  [ 2 posts ] 
Author Message
 Post subject: Query object created from a SQL select return empty list
PostPosted: Fri Sep 10, 2004 4:46 pm 
Newbie

Joined: Fri Sep 10, 2004 3:10 pm
Posts: 4
Hibernate version:
2.1

Mapping documents:
Merchant.hbm.xml
<hibernate-mapping package="...">
<class name="Merchant" table="MERCHANT" proxy="Merchant">
<id name="id" type="long" column="MERCHANTID">
<generator class="native"/>
</id>
<property name="name" column="NAME"/>
</class>
</hibernate-mapping>

Person.hbm.xml
<hibernate-mapping package="...">
<class name="Person" table="Person" proxy="Person">
<id name="id" type="long" column="PERSONID">
<generator class="native"/>
</id>
<property name="firstName" column="FIRSTNAME"/>
<property name="lastName" column="LASTNAME"/>
<property name="personalCode" column="PSC"/><!--
</class>
</hibernate-mapping>

Code between sessionFactory.openSession() and session.close():

String sql = "select {m}.MERCHANTID as {m.id}, {m}.NAME as {m.name} " + "from MERCHANT {m} join PERSON p on {m}.MERCHANTID=p.MERCHANTID " + "where p.PERSONID=" + person.getId();
Query sqlQuery = session.createSQLQuery(sql, "m", Merchant.class);
List merchants = sqlQuery.list();

Full stack trace of any exception that occurs:
No exception

Name and version of the database you are using:
Oracle 9.2
The generated SQL (show_sql=true):
select m.MERCHANTID as MERCHANTID0_, m.NAME as NAME0_ from MERCHANT m join PERSON p on m.MERCHANTID=p.MERCHANTID where p.PERSONID=110

Debug level Hibernate log excerpt:

Native SQL select returns a row but list generated by Query.list()
is empty. The schema contains more columns than the mapping.xml.
PERSON table has a column MERCHANTID besides PERSONID,
FIRSTNAME, LASTNAME and PSC. The native SQL joins the
MERCHANT and PERSON table on MERCHANTID to get the
Merchant for a Person. Why did the native SQL return one row
but the Hibernate method returned empty?

Thanks for ideas.

Shel


Top
 Profile  
 
 Post subject:
PostPosted: Sat Sep 11, 2004 2:49 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
you queried in a different database ?

Have you chekked in the hibernate log exactly what sql you are executing ?
Is that sql also returning 1 row ?
And if that is still true then step into the src of hibernate and see what happens with the result.

_________________
Max
Don't forget to rate


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