-->
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: HQL and many-to-many relations
PostPosted: Tue Nov 02, 2004 1:19 pm 
Newbie

Joined: Tue Nov 02, 2004 1:04 pm
Posts: 2
This is my data model.
Entity -> Account (accid, accbalance,...)
Entity -> Customer (custid, custlogin,...)

I have mapped a many2many relationship between Account and Customer (one customer can have many accounts and one account may belong to 1 or more customers). In the db I have created the table custacc to store the accid's and custid's. Everything works fine but got problems when trying to retrieve the Accounts of a given customer. Seems simple but I couldn't get the hql code for that query. The solution of obtaining the Customer and loop through the collection is not valid for me. Do I need to map the intermediate table custacc?

Thanks


Hibernate version: 2.1.6

Mapping documents:
<class name="es.dbbank.model.beans.Account" table="account">
<id name="accid" type="long" column="accid" unsaved-value="0">
<generator class="identity" />
</id>
<property name="accdate" column="accdate" type="date" />
<property name="acctype" column="acctype" type="string" />
<property name="accbalance" column="accbalance" type="double" />
<set name="customers" table="custacc" lazy="true">
<key>
<column name="accid" not-null="true"/>
</key>
<many-to-many class="es.dbbank.model.beans.Customer">
<column name="custid" not-null="true"/>
</many-to-many>
</set>
</class>

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

Full stack trace of any exception that occurs:

Name and version of the database you are using:

The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 02, 2004 1:22 pm 
Newbie

Joined: Tue Nov 02, 2004 1:04 pm
Posts: 2
sorry, but my post was submited without finishing (firefox strange behavior)

The mapping for Customer is:

<class name="es.dbbank.model.beans.Customer" table="customer">
<id name="custid" type="long" column="custid" unsaved-value="0">
<generator class="identity" />
</id>
<property name="custlogin" column="custlogin" type="string" />
<property name="custfirst" column="custfirst" type="string" />
<property name="custlast" column="custlast" type="string" />
<property name="custdate" column="custdate" type="date" />
<property name="custaddr" column="custaddr" type="string" />
<set name="accounts" table="custacc" lazy="true">
<key>
<column name="custid" not-null="true"/>
</key>
<many-to-many class="es.dbbank.model.beans.Account">
<column name="accid" not-null="true"/>
</many-to-many>
</set>
</class>


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.