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?