JPA / Hibernate有条件的onetomany关系? [英] JPA/Hibernate conditionally onetomany relationship?
问题描述
我使用Hibernate Tools直接从数据库生成DAO和类。在数据库中有两个表(表A和B),并且从A到B之间存在一对多关系(B中的多行映射到单个A)。
<在生成的A(A类)代码中,有一个B类集合,它反映了一对多关系。但是,我不需要属于A的所有B行都在结果中(比如,我只需要B行中列x为NULL的行)。我不明白这是如何实现的。任何想法?
非常感谢!
@Where
注释
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!
You can use the @Where
annotation
这篇关于JPA / Hibernate有条件的onetomany关系?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!