我需要獲得已在RoleGroupEntity表中分配了特定角色的GroupEntity對象。命名查詢加入選擇
我嘗試做這樣的:
@NamedQuery(name = "GroupEntity.getGIDs", query = "SELECT o FROM RoleGroupEntity u JOIN FETCH u.GroupId o WHERE u.role_id LIKE :role_id")
但我得到:
org.hibernate.QueryException: could not resolve property: role_id of: RoleGroupEntity
entites的樣本:
@Entity
@Table(name = "group")
public class GroupEntity implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Column(name = "gid_number")
private Long gid_number;
@OneToMany(cascade = CascadeType.ALL, mappedBy = "GroupId")
private List<RoleGroupEntity> GroupId;
RoleGroupEntity具有複合鍵:
@Entity
@Table(name = "role_group")
public class RoleGroupEntity implements Serializable {
private static final long serialVersionUID = 1L;
@EmbeddedId
private RoleGroupCompositeKey posRGKey;
@MapsId("role_id")
@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "role_id")
private RoleEntity roles;
@MapsId("group_id")
@ManyToOne
@JoinColumn(name = "group_id")
private GroupEntity GroupId;
你知道如何使我的選擇查詢工作嗎?
有一個在RoleGroupEntity沒有財產「ROLE_ID」的消息稱。 JPQL使用字段/屬性名稱而不是列名。 JPQL!= SQL –