-->
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: using "where" in hbm files on many-to-many
PostPosted: Tue May 23, 2006 7:54 am 
Newbie

Joined: Sat Feb 25, 2006 8:19 am
Posts: 7
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version: 3.1.3.

Mapping documents:

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

Full stack trace of any exception that occurs:

Name and version of the database you are using: oracle 10g

The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:

I have two classes - A and B. between them there's a uni-directional many-to-many relation. Only A class has a setOfBs. B class doesn't have any reference to A objects.
In my hbm file, I have the following bit regarding this set:
Code:
<set name="setOfBs" table="MEMBERS" lazy="true"
   cascade="none" sort="unsorted">
   <key column="A_ID"></key>
   <many-to-many class="example.B"
      column="B_ID" outer-join="auto" where="CODE = 2" />
   <sql-insert>
      insert into MEMBERS (A_ID, B_ID, CODE)
      values(?, ?, 2)
   </sql-insert>
</set>


The many-to-many relation uses the MEMBERS table, which is a normal many-to-many table, with an extra field of CODE, that I need in there (For other reasons).
Now I try to get a list of A objects, each with its set of B's, using this HQL command:
Code:
select distinct a from A inner join a.setOFBs


and the hibernate creates the following SQL command:
Code:
select distinct a.*
from A a
   inner join MEMBERS member
      on a.A_ID=member.A_ID
   inner join B b
      on member.B_ID=b.B_ID and b.CODE = 2



this SQL looks for the CODE in the B table, and of course it fails - the CODE is in the MEMBERS table. Is there something I can do in the xml mapping file, to tell hibernate this?


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.