createNativeQuery [英] createNativeQuery
本文介绍了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.NullPointerException
Query 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
推荐答案
是否可能未初始化em
?
em
是局部变量.我认为问题是由于在构造函数中调用public List<Receiptheader> retriveDetailedReceipts(String recDate, int poststatusid)
而引起的.我认为那是我的问题所在.如果我调用其他方法似乎在起作用.我认为在bean类的构造函数中调用方法可能会有问题.
em
is a local variable. Im thinking the problem is arising because im callingpublic List<Receiptheader> retriveDetailedReceipts(String recDate, int poststatusid)
in a constructor. I think thats where my problem is. If i call the method else where it seems to be working. I think there could be a problem with calling my method in the constructor of my bean class.
这篇关于createNativeQuery的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文