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
|