我有一个实体Ride,它嵌入了一个可嵌入的“实体” Route。Route有一个 List 属性towns与 ManyToMany 关系,所以它有 fetchtype LAZY (我不想使用 EAGER)。所以我想为实体Ride定义一个 NamedEntityGraph ,以加载一个带有实例化 List of towns的Route的Ride对象。但是当我部署我的战争时,我得到了这个例外:
java.lang.IllegalArgumentException:属性 [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 = GenerationType.AUTO)
private Long id;
@Embedded
private Route route;
// some getter and setter
}
路线
@Embeddable
public class Route implements Serializable {
private static final long serialVersionUID = 1L;
@ManyToMany
private List<Town> towns;
// some getter and setter
}