-->
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: Creating subcriteria of subcriteria problem
PostPosted: Thu Jun 19, 2008 12:27 pm 
Newbie

Joined: Tue Feb 19, 2008 6:48 am
Posts: 17
Hibernate version:
3.2.6

Mapping documents:

<hibernate-mapping>
<class name="A" table="A">
<id name="id" column="ID" type="long">
<generator class="sequence">
</id>

<set name="AB" table="AB" cascade="all-delete-orphan">
<key column="ID_A"/>
<one-to-many class="AB" />
</set>
</hibernate-mapping>


<hibernate-mapping>

<class name="AB" table="AB">
<composite-id name="id" class="AB$Id">
<key-many-to-one name="entidade" class="A" column="ID_A" />
<key-many-to-one name="entidade" class="B" column="ID_B" />
</composite-id>

<many-to-one name="role" class="Role" column="ID_ROLE" />
</class>
</hibernate-mapping>


<hibernate-mapping>
<class name="B" table="B">
<id name="id" column="ID" type="long">
<generator class="sequence">
</id>

<property name="field1" column="field1" type="string" />
<set name="AB" table="AB">
<key column="ID_B"/>
<one-to-many class="AB" />
</set>
</hibernate-mapping>


Name and version of the database you are using:
Oracle10g


I have 2 entities related by an association class, an i want using a criteria with entity A to filter using a property of entity B.

Code:
Criteria select = getSession().createCriteria(A.class);
Criteria ab = select.createCriteria("ab");
Criteria b = ab.createCriteria("id.b");
b.add(Restrictions.eq("field1", "100"));


However the generated sql only does one join, between A and AB, although it references the field1 of table B. Here is the query:

SELECT (...)
FROM a this_ INNER JOIN ab thisab_ ON this_.ID = thisab_.id_a
WHERE servicoonl2_.field1 = ?

The servicoonl2_ wich correspond to the Table B is not declared in the query, so a ORA-00904: invalid identifier error ocurrs.

I don't know if i can actually do a subquery of subquery. I already found a solution using HQL, but i would like to know what i am doing wrong here...

Thanks for you help.

_________________
João Simas


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.