我是 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
最佳答案
Criteria
创建于Document
实体,并且您正在尝试访问属性 clientId
Document
中不存在该内容实体,所以 hibernate 给你一个异常(exception)。
关于java - Hibernate 标准第 2 期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25798265/