on 10-05-2009 7:24 AM
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.
thks
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
87 | |
10 | |
10 | |
10 | |
7 | |
6 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.