-->
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: Hibernate mapping "where" clause for associations
PostPosted: Mon Sep 24, 2007 3:24 pm 
Newbie

Joined: Wed Aug 29, 2007 8:43 am
Posts: 5
Location: Philahttps://forum.hibernate.org/ucp.php?i=profile&mode=reg_detailsdelphia, PA
I am curious about the arbitrary "where" clause in a Hibernate mapping file. The only information I have found on it is the following (from the Reference Guide):

"specify an arbitrary SQL WHERE condition to be used when retrieving objects of this class"

My question is: if I add a where clause to a Hibernate mapping file for class A, does that apply to associations as well? For instance, let's say I have the following classes:

Code:
public class Teacher {

  private Set<Course> activeCourses;

}

Code:
public class Course {

  private Teacher teacher;
  private boolean active;

}


Let's say I want to restrict the set of courses for a teacher to be only the active ones. I know that I can update the course mapping file to include the necessary where clause to mandate that Courses be "active". However, will that mean that after loading a Teacher, its persistent set of Courses will also only contain active Courses?

I hope this is the case; in my real-world example, we have several classes that are in persistent sets for many others classes. It would be nice to only define that restriction in one place (e.g. the Course.hbm.xml file).

Like I said, our case is more complicated, so it would be great if this functionality exists. If not, is there some other Best Practice method of handling this?

Thanks for any help anyone can offer.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 25, 2007 9:13 am 
Newbie

Joined: Wed Aug 29, 2007 8:43 am
Posts: 5
Location: Philahttps://forum.hibernate.org/ucp.php?i=profile&mode=reg_detailsdelphia, PA
Well if anyone is interested, I tested this, and it does not appear that the "where" clause affects collections of the class in question. This means that the "where" clause needs to be included in each association mapping as well. This is not ideal but it also isn't the end of the world.


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.