Well, I've changed my code to use HQL and I've stripped my query down. It is retrieving a DtsVi object which contains a Set of DtsViLineItems. There is a one-to-many relationship. DtsVi and DtsViLineItems contain composite keys. I want to return a list of DtsVi objects along with their corresponding DtsViLineItems, but I still get an empty set of DtsViLineItems. Why?
Code:
String hqlSelect ="select d from DtsVi d left outer join d.lineItems li where d.dtsViPK.identDealerNumber = ? ";
results = getHibernateTemplate().find(hqlSelect,dealerNbr);
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping
>
<class
name="com.sumware.model.DtsVi"
table="starViInvoice"
>
<!-- Use of @hibernate.id for composite IDs is deprecated, use @hibernate.composite-id instead -->
<composite-id
name="dtsViPK"
class="com.sumware.model.DtsViPK"
unsaved-value="any"
>
<!-- Defining the key-property element from @hibernate.property tags is deprecated, use @hibernate.key-property instead -->
<key-property
name="headerOrderReference"
type="java.lang.String"
>
</key-property>
<!-- Defining the key-property element from @hibernate.property tags is deprecated, use @hibernate.key-property instead -->
<key-property
name="identDealerNumber"
type="java.lang.String"
>
</key-property>
<!-- Defining the key-property element from @hibernate.property tags is deprecated, use @hibernate.key-property instead -->
<key-property
name="manufacturer"
type="java.lang.Integer"
>
</key-property>
</composite-id>
<many-to-one
name="vehicle"
class="org.appfuse.model.Vehicle"
column="headerOrderReference"
unique="true"
insert="false"
update="false"
property-ref="prodNbr"
>
</many-to-one>
<set
name="lineItems"
lazy="true"
cascade="all"
>
<!-- @hibernate.collection-key tag is deprecated, use @hibernate.key instead -->
<key
>
</class>
</hibernate-mapping>
Code:
<hibernate-mapping
>
<class
name="com.sumware.model.DtsViLineItem"
table="starViLineItem"
>
<!-- Use of @hibernate.id for composite IDs is deprecated, use @hibernate.composite-id instead -->
<composite-id
name="dtsViLineItemPK"
class="com.sumware.model.DtsViLineItemPK"
unsaved-value="any"
>
<!-- Defining the key-property element from @hibernate.property tags is deprecated, use @hibernate.key-property instead -->
<key-property
name="lineNumber"
type="java.lang.Integer"
>
</key-property>
<!-- Defining the key-property element from @hibernate.property tags is deprecated, use @hibernate.key-property instead -->
<key-property
name="headerOrderReference"
type="java.lang.String"
>
</key-property>
<!-- Defining the key-property element from @hibernate.property tags is deprecated, use @hibernate.key-property instead -->
<key-property
name="identDealerNumber"
type="java.lang.String"
>
</key-property>
<!-- Defining the key-property element from @hibernate.property tags is deprecated, use @hibernate.key-property instead -->
<key-property
name="manufacturer"
type="java.lang.Integer"
>
</key-property>
</composite-id>
<property
name="description"
column="description"
length="30"
>
</property>
<property
name="optionPackage"
>
<column
name="optionPackage"
length="7"
/>
</property>
</class>
</hibernate-mapping>