嗨我有postgresql db的这两个基本实体映射,我已经为其编写了标准 获取具有相同密钥的所有激活用户,它显示此错误
org.hibernate.QueryException: could not resolve property: key.id of: com.sar.dfsapp.modal.ActivatedUser
@Entity
@Table(name = "activated_user")
public class ActivatedUser implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id", nullable = false, length = 11)
private long id;
@ManyToOne
@JoinColumn(name = "key_id", nullable = false)
private Key key;
}
@Entity
@Table(name = "key")
public class Key implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id", nullable = false, length = 11)
private long id;
@Column(name = "key_code", nullable = false)
private String keyCode;
}
以下是我尝试的标准。
Criteria c = getSession().createCriteria(ActivatedUser.class);
c.add(Restrictions.eq("key.id", id));
List<ActivatedUser> result = c.list();
答案 0 :(得分:0)
试试这个:
Criteria c = getSession().createCriteria(ActivatedUser.class);
Criteria keyCriteria = criteria.createCriteria("key", CriteriaSpecification.INNER_JOIN);
keyCriteria.add(Restrictions.eq("id", id));
List<ActivatedUser> result = c.list();
有同样的错误吗?