I have a somewhat complicated schema where I want to do some magic to make a part of it more transparent. Basically I want something like this:
Code:
@Entity
public class Enclosed {
@ManyToOne
private Container container;
};
@Entity
public class Container {
@OneToMany(mappedBy="container")
private List<Enclosed> enclosed;
}
@Entity
public class UnContained {
@OneToMany
@Where(clause="container IS NULL")
private List<Enclosed> enclosed;
}
Basically, this would allow me to access the Enclosed elements that have no parent (which is a valid state).
I can't figure out how to do this in Hibernate Annotations without doing it by hand (i.e. by custom code that gets the list via an HQL query). Is there any way to do this? It is a database with much history, though it can be changed, I'd rather keep changes to a minimum.