本文介绍了createNativeQuery的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在我的EJB项目中,我有一个带有以下方法的会话bean,该方法以日期和整数作为参数.
In my EJB project i have a session bean with the following method that takes in a date and integer as arguments.
public List<Receiptheader> retriveDetailedReceipts(String recDate, int poststatusid){
System.out.println("******* "+ recDate + " ******** "+ poststatusid);
String query = "SELECT r.receiptnumber AS receiptnumber_, r.receiptdate AS receiptdate_, " +
"r.receiptamount AS receiptamount_, r.postdate AS postdate_, " +
"t.INTERFACETYPE AS interfacetype_, i.DESCRIPTION AS interfaces_ " +
"FROM receiptheader r, interfacetypes t, interfaces i " +
"WHERE r.INTERFACETYPEID = t.INTERFACETYPEID " +
"AND r.INTERFACEID = i.INTERFACEID AND r.RECEIPTDATE = ''" + recDate +"'' "+
"AND r.POSTSTATUSID = " + poststatusid;
System.out.println(query);
try{
Query q = em.createNativeQuery(query,"Receiptdetail");
List<Receiptheader> rec = q.getResultList();
return rec;
}catch(Exception e){
e.printStackTrace();
}
return null;
}
}
我在
的行上得到了java.lang.NullPointerExceptionQuery q = em.createNativeQuery(query,"Receiptdetail");
我在下面有一个实体
I am getting a java.lang.NullPointerException on the line with Query q = em.createNativeQuery(query,"Receiptdetail");
I have an entity below
@Entity
@SqlResultSetMapping(name="Receiptdetail",
entities={
@EntityResult(entityClass=Receiptheader.class,
fields={
@FieldResult(name="receiptnumber", column="receiptnumber_"),
@FieldResult(name="receiptdate", column="receiptdate_"),
@FieldResult(name="receiptamount", column="receiptamount_"),
@FieldResult(name="postdate", column="postdate_"),
}),
@EntityResult(entityClass=Interfacetypes.class,
fields={
@FieldResult(name="interfacetype", column="interfacetype_")
}),
@EntityResult(entityClass=Interfaces.class,
fields={
@FieldResult(name="description", column="interfaces_")
})})
public class Receiptheader implements Serializable {
在我的代码中被称为我似乎无法理解错误是什么.请帮助
that is called in my code. I cant seem to understand what the error is. Please help
推荐答案
这篇关于createNativeQuery的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!