-->
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.  [ 4 posts ] 
Author Message
 Post subject: How to access parent and set element in HQL in Filter
PostPosted: Fri Oct 21, 2005 10:12 am 
Beginner
Beginner

Joined: Thu Jun 02, 2005 9:36 am
Posts: 20
Hibernate version:
3.1 b1
Name and version of the database you are using:
MySQL
Mapping documents:
<hibernate-mapping>
<union-subclass name="pkg.User" table="User" extends="Entity">
<property name="name" unique="true"/>
<set name="something" table="UserSomething" cascade="persist,merge,save-update">
<key column="userId"/>
<many-to-many column="somethingId" class="pkg.Something"/>
<filter name="currentUser"
condition="FROM Extra e WHERE e.:user = User.this AND e.target = Portal.this AND e.include = 1"/>
</set>
</union-subclass>
<filter-def name="currentUser">
<filter-param name="user" type="pkg.User"/>
</filter-def>
</hibernate-mapping>

This is a followup question to:
http://forum.hibernate.org/viewtopic.php?t=949142

Okay, my pseudo attempt above might show what I'm trying to do. I want to create a filter that joins to a different table (Extra) and joins on Extra.user = the User and Extra.target = the portal in the set in question and then the real filter is that e.include = 1.

How would this be done correctly?

Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 21, 2005 1:11 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
correlated subquery


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 21, 2005 1:19 pm 
Beginner
Beginner

Joined: Thu Jun 02, 2005 9:36 am
Posts: 20
Thank you for the response, but it doesn't answer my whole question. What is the right way to access the portal and user object in the where clause?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 21, 2005 3:30 pm 
Beginner
Beginner

Joined: Thu Jun 02, 2005 9:36 am
Posts: 20
Well, I didn't figure out the answer to my question exactly, but I did get the filter to work. By showing the SQL I figured out that the local context in the query is the join table UserSomething and so I can get somethingId from that.


<filter name="currentUser"
condition="EXISTS( SELECT 1 FROM Extra e WHERE e.user = :userId AND e.target = somethingId AND e.include = 1)" />

Thanks for the tip on starting with a correlated subquery.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.