-->
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: problem filtering results on one-to-many with where clause
PostPosted: Thu Feb 23, 2006 3:53 pm 
Newbie

Joined: Mon Dec 05, 2005 5:26 pm
Posts: 2
I am having an issue when trying to map a (one-to-many) association.

The child object is based off of two tables (using a join), and the parent object needs to filter the results (using a where clause on the set) using two columns, one from each of the tables that the child object is based on.

Hibernate version: 3.1.2

Mapping documents:

Mapping Document 1:

<hibernate-mapping>

<class name="A" table="A">

<id name="id" type="java.lang.Integer">
<column name="A_NUM"/>
</id>

<property name="aProperty1">
<column name="A_FIELD_1" not-null="true"/>
</property>

<set name="setOfBs" where="B1_FIELD_1 = 0 AND B2_FIELD_1 = 1">
<key column="B_A_NUM"/>
<one-to-many class="B" />
</set>

</class>

</hibernate-mapping>


Mapping Document 2:

<hibernate-mapping>

<class name="B" table="B1">

<id name="id" type="java.lang.Integer">
<column name="B1_NUM"/>
</id>

<property name="b1Property1">
<column name="B1_FIELD_1" not-null="true"/>
</property>

<join table="B2">
<key column="B2_B1_NUM" />

<property name="b2Property1">
<column name="B2_FIELD_1" />
</property>

</join>

</class>

</hibernate-mapping>

Name and version of the database you are using: Oracle 8i

The generated SQL (show_sql=true):

where b0_.B1_NUM=b0_1_.B2_B1_NUM and b0_.B1_FIELD_1 = 0 AND b0_.B2_FIELD_1 = 1

As you can see from the extracted where clause, both fields in the where (B1_FIELD_1 and B2_FIELD_1) are being prefixed with the generated alias for the root table B1. the where should read:

where b0_.B1_NUM=b0_1_.B2_B1_NUM and b0_1_.B1_FIELD_1 = 0 AND b0_.B2_FIELD_1 = 1

Any help is much appreciated!

Thanks!


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.