-->
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: Criteria on none mapping class
PostPosted: Sat Mar 29, 2008 3:08 pm 
Beginner
Beginner

Joined: Sun Aug 12, 2007 11:22 am
Posts: 44
Location: Sweden
Hi!

Is it possible to join two classes that hasn't got a bidirectional mapping?

Here's the scenario. I have an Item class that has a mapping to a SubCategory. Every entity has a Translation class but the translation class is only aware of the entity and not visa versa.

ItemTranslation has an Item
Item is not aware of ItemTranslation
SubCategoryTranslation has an SubCategory
SubCategory is unaware of the SubCategoryTranslation
Item has a Subcategory

In my criteria I start from ItemTranslation and add alias for the item
and the subcategory. createAlias( Item , itemTranslation.Item )
createAlias( subcategory , item.Subcategory ). Is it possible to reference SubCategoryTranslation here?


Top
 Profile  
 
 Post subject:
PostPosted: Sun Mar 30, 2008 6:38 am 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
You can achieve something like that with a detached criteria and a subquery (as long as you only want to filter on SubCategoryTranslation and not fetch them).

Code:
DetachtedCriteria det =
    DetachedCriteria.For(typeof(SubCategoryTranslation ), "sct")
      .Add( Expression.EqProperty( "sct.SubCategoryId", "subcategory.Id" ) );

det.Add(Expression.Eq(...


and then add this detached criteria as a subquery to your first criteria:

Code:
criteria.Add( Subqueries.Exists(
          det.SetProjection( Projections.Property( "Id" ) ) ) );

_________________
--Wolfgang


Top
 Profile  
 
 Post subject:
PostPosted: Sun Mar 30, 2008 7:50 am 
Beginner
Beginner

Joined: Sun Aug 12, 2007 11:22 am
Posts: 44
Location: Sweden
Thanks!

I would have liked to set a Transformers.AliasToBean for this. I will try!


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.