Reputation: 2607
I'm trying to fetch results using select query of HQL of Hibernate. However its throwing an error. My code and model class as follows.
package com.chni;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
@Entity
public class Dashboard {
@Override
public String toString() {
return "Dashboard [uid=" + uid + ", keyname=" + keyname + ", dbvalue="
+ dbvalue + ", getUid()=" + getUid() + ", getKeyname()="
+ getKeyname() + ", getDbvalue()=" + getDbvalue()
+ ", getClass()=" + getClass() + ", hashCode()=" + hashCode()
+ ", toString()=" + super.toString() + "]";
}
@Id
@GeneratedValue
private int dbid;
private String uid;
private String keyname;
private String dbvalue;
public String getUid() {
return uid;
}
public void setUid(String uid) {
this.uid = uid;
}
public String getKeyname() {
return keyname;
}
public void setKeyname(String keyname) {
this.keyname = keyname;
}
public Dashboard(String uid, String keyname, String dbvalue) {
super();
this.uid = uid;
this.keyname = keyname;
this.dbvalue = dbvalue;
}
public String getDbvalue() {
return dbvalue;
}
public void setDbvalue(String dbvalue) {
this.dbvalue = dbvalue;
}
}
String hql = "FROM com.chni.Dashboard where uid = "+userId;
Query query = session.createQuery(hql);
System.out.println(query.list());
List<Dashboard> listUserDetails = query.list();
for (Dashboard user : listUserDetails) {
System.out.println(user.getUid());
}
Error is as follows
Feb 19, 2016 4:05:37 PM org.hibernate.hql.internal.QueryTranslatorFactoryInitiator initiateService
INFO: HHH000397: Using ASTQueryTranslatorFactory
Hibernate:
select
dashboard0_.dbid as dbid1_0_,
dashboard0_.dbvalue as dbvalue2_0_,
dashboard0_.keyname as keyname3_0_,
dashboard0_.uid as uid4_0_
from
Dashboard dashboard0_
where
dashboard0_.uid=2
org.hibernate.InstantiationException: No default constructor for entity: : com.intu.Dashboard
at org.hibernate.tuple.PojoInstantiator.instantiate(PojoInstantiator.java:81)
at org.hibernate.tuple.PojoInstantiator.instantiate(PojoInstantiator.java:101)
I have searched other stack questions with similar errors, but couldn't able to figure it out the exact issue. Am I missing anything in the code or POJO?
Upvotes: 0
Views: 898
Reputation: 57421
Just add a constructor without parameters
public Dashboard() {}
Upvotes: 1