views:

45

answers:

2

Hi,

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 idea?

Thanks a lot!

+1  A: 

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.

Balint Pato
+1  A: 

You can use the @Where annotation

Bozho