-->
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.  [ 1 post ] 
Author Message
 Post subject: join question
PostPosted: Wed Feb 13, 2008 11:47 am 
Newbie

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.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.