Joined: Thu Jan 03, 2008 3:05 pm Posts: 6
|
Hello,
I need to pull up a customer object with its addresses using HQL. Note that the relation is between a customer and an address are a common state. If the address doesn't have a state we also return that as an address for every customer.
I have the following situation:
1. A customer object which has a collection of addresses:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
namespace="X" assembly="X">
<class name="Customer" table="customers" discriminator-value="0">
<id name="ID" type="System.Guid" unsaved-value="00000000-0000-0000-0000-000000000000">
<column name="customerId" not-null="true" sql-type="uniqueidentifier"/>
<generator class="guid" />
</id>
<property name="Name" type="System.String" column="name" not-null="false" length="50" />
<property name="StateId">
<column name="stateId" not-null="false" />
</property>
</class>
</hibernate-mapping>
2. Address mapping
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
namespace="X" assembly="X">
<class name="Address" table="addresses">
<id name="AddressId" type="System.Int32" unsaved-value="0">
<column name="addressId" not-null="true" sql-type="int"/>
<generator class="identity" />
</id>
<property name="StateId">
<column name="stateId" not-null="false" />
</property>
<property name="Street">
<column name="street" not-null="true" />
</property>
</class>
</hibernate-mapping>
3. My goal is to pull up a customer with a list of addresses.
Because of some other reason I have to use this HQL query:
FROM Customer c WHERE c.StateID = :StateID or c.StateID is null
I need help adjusting the above HQL to return the list of addresses along with the customer.
Note the address is not mapped to the customer. I had this before but that didn't work either.
|
|