我有一个场景,我需要在一种情况下加载所有子值,在另一种情况下加载一些特定的子值。我在这两种情况下都使用一个 bean,并使用命名查询编写查询。
@namedqueries{
@namedQuery(name="query1") = "select parent from Parent parent",
@namedQuery(name="query2") = "select parent from Parent parent",
}
Class Parent {
@manytomany
@join mentioned my join condition here //
List<Child> child ;
}
Class Child
{
String A;
String B;
String C;
@manytomany(mappedby = "child")
List<parent> parent ;
}
现在在我的查询 2 中,我只需要加载 String A 而不是 String B 和 String C 。我尝试使用
"select parent.child .A from Parent parent" as Query 2
但得到以下错误
"Attempting to navigate to relation field via multi-valued association and
jpql doesnt allow traversal through multi valued relationship. Try join instead"
因此,有关如何进行此操作的任何建议..
1) Should I have to create a new bean for each Query
2) Or Can we control the child object parameters in specific named queries