Hibernate标准问题2

时间:2014-09-11 23:00:43

标签: java hibernate criteria

我是Hibernate和Criteria的新手,我对以下内容有点麻烦。 我试图得到一份文件清单,我所拥有的唯一数据就是客户ID。是否有可能通过Hibernate获取数据?

我有以下实体

@Entity
public class Document implements Serializable {

    @Id
    @GeneratedValue(strategy=GenerationType.AUTO)
    private Long id;

   @OneToMany(fetch=FetchType.LAZY)  
   @JoinColumn(name="documentId", referencedColumnName="id")  
    private List<Gd_Client> clientList;
   (...)

@Entity
public class Gd_Client implements Serializable {

@Id
private long clientId;
@Id
private String SecId;

(...)

在DAO中:

public List<Document> getDocumentsbyClientId(Long clientId) {

    Session session = entityManager.unwrap(Session.class);
    Criteria crit = session.createCriteria(Document.class);

    crit.add(Restrictions.eq("clientId",clientId));

    return crit.list();

}

我收到以下错误:

ERROR: Parameter #1 has not been set.
09/11/2014 11:27:44 com.opensymphony.xwork2.util.logging.commons.CommonsLogger error
WARNING: Exception occurred during processing request: could not execute query
org.hibernate.exception.SQLGrammarException: could not execute query

1 个答案:

答案 0 :(得分:1)

Criteria实体上创建了Document,并且您正在尝试访问clientId实体中不存在的属性Document,因此hibernate会为您提供异常。