cancel
Showing results for 
Search instead for 
Did you mean: 

How to handle javax.persistence.NoResultException

Former Member
0 Kudos

Dear All,

I am using EJB3. In my session bean when i get the result from persistence manager it will throw javax.persistence.NoResultException when no result selected. Due to this next step will not execute. How to handle such types of exception ?

My code looks like:

Query query =em.createQuery("SELECT o.fPAccountId, sum(o.amount) FROM FPAccountTransaction o where o.branchId =:pbranchId and o.transactionDate = ptransactionDate and o.planned <> 0 group by o.fPAccountId ");

query.setParameter("pbranchId", branchId);

query.setParameter("ptransactionDate", asOnDate);

System.out.println("query:"+ query);

List<FPAccountTransaction> list = query.getResultList();

The last line cause to throw exception when not result found through select query.

Accepted Solutions (0)

Answers (3)

Answers (3)

Former Member
0 Kudos

thks

former_member185086
Active Contributor
0 Kudos

Hi

Have a look on this [doc|http://www.sdn.sap.com/irj/scn/index?rid=/library/uuid/b002681d-0e01-0010-73a5-ff70f8005476&overridelayout=true]

BR

Satish Kumar

Former Member
0 Kudos

Hi kapitsu,

Add one 'if' condition. if query not equal to null then you execute query.getResultList().

Query query =em.createQuery("SELECT o.fPAccountId, sum(o.amount) FROM FPAccountTransaction o where o.branchId =:pbranchId and o.transactionDate = ptransactionDate and o.planned 0 group by o.fPAccountId ");

query.setParameter("pbranchId", branchId);

query.setParameter("ptransactionDate", asOnDate);

System.out.println("query:"+ query);

if(query!=null)

{

List<FPAccountTransaction> list = query.getResultList();

}

Regards,

Sunaina Reddy T

Former Member
0 Kudos

Sunaina ji,

If query is null then it will throw null pointer exception i think. what is the relation of NoResultException with query object?? sorry i m not getting the point ??

Edited by: kapitsu on Oct 5, 2009 10:25 AM

Edited by: kapitsu on Oct 5, 2009 10:26 AM