2016-08-10 50 views
0

嗨,我有PostgreSQL的分貝這兩個基本的實體映射,我已經寫了標準 提取具有相同的密鑰的所有激活用戶其顯示的錯誤Hibernate的標準不能讀取行未能解決物業

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

試試這個:

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(); 

它有同樣的錯誤?

相關問題