我有一个实体Ride,它嵌入了一个可嵌入的"实体" 路径.路线有一个列表属性城镇与多对多的关系,所以它有fetchtype LAZY(我不希望使用EAGER).所以我想定义的实体NamedEntityGraph 平顺,加载加载骑一个物体路线与instantied名单城镇.但是当我部署战争时,我得到了这个例外:
java.lang.IllegalArgumentException:Attribute [route]不是托管类型
骑
@Entity
@NamedQueries({
@NamedQuery(name = "Ride.findAll", query = "SELECT m FROM Ride m")})
@NamedEntityGraphs({
@NamedEntityGraph(
name = "rideWithInstanciatedRoute",
attributeNodes = {
@NamedAttributeNode(value = "route", subgraph = "routeWithTowns")
},
subgraphs = {
@NamedSubgraph(
name = "routeWithTowns",
attributeNodes = {
@NamedAttributeNode("towns")
}
)
}
)
})
public class Ride implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = …Run Code Online (Sandbox Code Playgroud) 我有一个父母与一个孩子表的OneToMany关联。
我正在尝试使用CriteriaBuilder编写查询,以限制从Child表返回的结果。
我要添加一个谓词,例如
cb.equal(parent.get("children").get("sex"), "MALE")
Run Code Online (Sandbox Code Playgroud)
如果父母有儿子或儿子和女儿,则是在返还该父母的同时还返还他们所有的孩子。
Hibernate使用我的谓词触发第一个查询,但是第二个获取子项的查询仅在不包含where子句的情况下使用JoinColumn
cb.equal(parent.get("children").get("sex"), "MALE").
Run Code Online (Sandbox Code Playgroud)
有什么想法吗?
我正在使用SetJoin
children = parent.joinSet("children", JoinType.LEFT)
Run Code Online (Sandbox Code Playgroud)
澄清:
public static Specification<Parent> findPlanBenefits(Integer parentId) {
return (parent, query, cb) -> {
Predicate predicates = cb.conjunction();
List<Expression<Boolean>> expressions = predicates.getExpressions();
//Parent Criteria
expressions.add(cb.equal(parent.get("parentId"), parentId));
//Children Criteria
SetJoin<Parent, Children> children = parent.joinSet("children", JoinType.LEFT);
Predicate sex = cb.equal(children.get("sex"), "MALE");
children.on(sex);
return predicates;
};
}
Run Code Online (Sandbox Code Playgroud) I'm trying to run a query where I get specific Work done by a Customer based of their id. I'm having troubles making a queue with JPQL that will actually retrieve all the data based on the foreign key of the customerId.
I've tried SELECT w FROM WorkEntry w WHERE w.customerId = 1 and that doesn't work. Every time I try to run it using the Persistence Unit testing I get the following error:
java.lang.IllegalArgumentException: An exception occurred while …