我试图从DataBase中检索数据时得到这个奇怪的异常。我得知它无法将它提取的数据转换为我的pojo类但我不明白为什么并且堆栈跟踪没有给出任何指示。 Pojo CLass
package en.vod.beans;
import java.sql.Clob;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
@Entity
@Table(name = "table_fault")
public class casedetails {
@Column(name = "title")
private String title;
@Id
@Column(name = "number")
private String fasoid;
@Column(name = "case_type_lvl1")
private String language;
@Column(name = "case_history")
private Clob casehistory;
@Column(name = "fault_status")
private String work_function;
@Column(name = "fault_id")
private String lid ;
@Column(name = "customer_responsible_group")
private String newMail ;
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getFasoid() {
return fasoid;
}
public void setFasoid(String fasoid) {
this.fasoid = fasoid;
}
public String getLanguage() {
return language;
}
public void setLanguage(String language) {
this.language = language;
}
public Clob getCasehistory() {
return casehistory;
}
public void setCasehistory(Clob casehistory) {
this.casehistory = casehistory;
}
public String getWork_function() {
return work_function;
}
public void setWork_function(String work_function) {
this.work_function = work_function;
}
public String getLid() {
return lid;
}
public void setLid(String lid) {
this.lid = lid;
}
public String getNewMail() {
return newMail;
}
public void setNewMail(String newMail) {
this.newMail = newMail;
}
}
以下是执行db查询的代码
public static casedetails read(String companyID) {
casedetails detilsfaso = new casedetails();
Session session = BaseDao.getSessionFactory();
detilsfaso = (casedetails) session.createQuery("Select title,fasoid,language,casehistory,work_function,lid,newMail FROM casedetails where fasoid = '" + companyID + "'");
session.close();
return detilsfaso;
}
错误如下
[org.jboss.as.webservices.invocation.InvocationHandlerJAXWS] (http-//localhost:8080-5) JBAS015594: Method invocation failed with exception: [Ljava.lang.Object; cannot be cast to en.vod.beans.casedetails: java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to en.vod.beans.casedetails
答案 0 :(得分:0)
你有一个ClassCastException,因为Session的方法createQuery(String queryString)返回Query,而不是你要查询的实体。