-->
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: Filtered OneToOne mappings
PostPosted: Wed Jul 02, 2008 7:38 pm 
Newbie

Joined: Wed Jul 02, 2008 7:29 pm
Posts: 3
So assume you have two entities, School and Student and obviously there is a one to many relationship. But the student entity has a column called valedictorian, and one of these students has the value 'Y', whereas all the rest have 'N'. (or you can come up with some more complex way of determining that from the student entity, if that hurts your sensibilities).

What i'd like is to have a field on School

Code:
@Entity
public class School
  implements Serializable {

    @OneToOne(fetch=FetchType.LAZY)
    @JoinColumn(name="STUDENT_ID")
    @Filter (condition="VALEDICTORIAN = 'Y', name="foo") 
  private Student valedictorian;
}


or something like that where i get a reference to one student out of a bunch of them based on the value of a field in that student entity.


Can i do this?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 07, 2008 8:55 am 
Expert
Expert

Joined: Tue May 13, 2008 3:42 pm
Posts: 919
Location: Toronto & Ajax Ontario www.hibernatemadeeasy.com
You know, I can't help but think this might not be done very easily with a simple Hibernate Query Language (HQL) or Hibernate Criteria Query. No?

_________________
Cameron McKenzie - Author of "Hibernate Made Easy" and "What is WebSphere?"
http://www.TheBookOnHibernate.com Check out my 'easy to follow' Hibernate & JPA Tutorials


Top
 Profile  
 
 Post subject: Formulas perhaps
PostPosted: Thu Jul 10, 2008 6:06 pm 
Newbie

Joined: Wed Jul 02, 2008 7:29 pm
Posts: 3
My best guess is that you can use a Formula discriminator to do this, but the documentation isn't clear enough for my little head.


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.