JPA/Hibernate conditionally onetomany relationship?
I am using Hibernate Tools to generate the DAO and classes straight from database. There are two tables (table A and B) in the database, and there is a one to many relationship from A to B (multiple rows in B mapped to single A).
In the generated code of A (class A), there is a collection of class B, which reflects the one to many relationship. However, I don't need all the rows of B that belong to A to be in the result (say, I only want rows from B where column x is NULL). I don't see how this can be achieved. Any 开发者_如何学JAVAidea?
Thanks a lot!
You can use the @Where
annotation
I suggest you using inheritance to solve the problem not a "flag" mechanism (i.e. using a "field value is null") as such, and then you'll have real OneToMany.
Though you could use Filters - the problem with this is that it's Hibernate specific and not JPA annotation.
精彩评论