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?