-->
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.  [ 2 posts ] 
Author Message
 Post subject: Mapping associations, filtered by join?
PostPosted: Wed Apr 04, 2007 4:19 pm 
Newbie

Joined: Fri Apr 30, 2004 12:32 pm
Posts: 3
I'm using Hibernate with a legacy database that has an association table between two other tables. Unfortunately, sometimes either of the things being associated can go into an inactive state without the related association being removed, and there is no state field on the association table itself. When I deal with this table, I do not want to get back rows from the association table where items on either side of the association are in non-active states.

Here is simplistic example of the situation:
Code:
table boys
    int     b_id
    int     b_status
    varchar b_name

table girls
    int     g_id
    int     g_status
    varchar g_name

table dating
    int     d_id
    int     b_id
    int     g_id
In this example, boys or girls are active when their status is 0, and inactive for any other status. If either becomes inactive (I dunno, maybe they move to another town!), the dating association is considered inactive, but it is not reflected directly in the association table.

Is there a way to set up the mapping so that when I deal with this association table, rows where either side of the association have a non-active status will automatically not be returned?

In other words, something like <class where="[sql statements]">, but joining against these other tables? Which, I understand, <class where=""> does not support.

Thanks,

Nick


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 04, 2007 11:48 pm 
Newbie

Joined: Mon Oct 23, 2006 11:03 pm
Posts: 17
Take a look in the documentation section 7.5.3 (link below) and map the
bidirectional relationship with <set> on either side, which does allow
where clauses.

http://www.hibernate.org/hib_docs/v3/re ... l-join-m2m


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