Reputation: 13
im new to Hibernate and Criteria and im getting a little trouble with the following. Im trying to get a list of documents and the only data i have it's the client Id. Is it possible to get the data by Hibernate?
I've got the following entities
@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;
(...)
And in the 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();
}
I get the following error:
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
Upvotes: 0
Views: 47
Reputation: 21445
The Criteria
is created on Document
entity and you are trying to access a property clientId
that is not there in Document
entity, so hibernate gives you an exception.
Upvotes: 1