-->
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.  [ 3 posts ] 
Author Message
 Post subject: <any> mapped properties in criteria queries
PostPosted: Wed Feb 07, 2007 1:50 pm 
Expert
Expert

Joined: Tue Aug 23, 2005 5:52 am
Posts: 335
Does anyone know if there's a format for finding entities mapped using <any> through a criteria query?

For example, if I have a User object with an Owner property which is mapped using <any> in HQL I could use something like:

<code>FROM User u WHERE u.Owner.id = :Id AND u.Owner.class = :Class</code>

In other words, is there a way to access the User based on a specific Owner in criteria?

Cheers,

Symon.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 07, 2007 2:30 pm 
Contributor
Contributor

Joined: Sat Sep 24, 2005 11:25 am
Posts: 198
to the best of my knowledge, there is no way to directly do this.

A roundabout way may be:


Code:

DetachedCriteria dc = DetachedCriteria.For(typeof(User), "user"))
.Add(Property.ForName("user.Owner").Eq("owner"));

session.CreateCriteria(typeof(BankAccount), "owner")
.Add(Subqueries.Exists(dc) ).List();




Note that I haven't tested this, but this is the general approach


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 07, 2007 6:50 pm 
Expert
Expert

Joined: Tue Aug 23, 2005 5:52 am
Posts: 335
Thanks Ayende.

I should have prefaced my question with the fact that I'm using NH 1.0.4 at th e moment... :P

Interesting example though...looks like there have been a lot of changes to the criteria model between versions!

Thanks for your help.

Cheers,

Symon


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