I have two Stateless Session Beans, XBean and YBean. They are looking as follows:
@Stateless
public class XBean implements XBeanLocal {
@PersistenceContext
private EntityManager em;
@EJB
private YBeanLocal yBean;
public void doSomething() {
try {
String value = "aValue";
yBean.doAnything(param);
} catch (NoResultException nre) {
//UNREACHABLE CODE!!!
System.out.println("Catched NoResultException!");
}
}
@Stateless
public class YBean implements YBeanLocal {
@PersistenceContext
private EntityManager em;
public AnEntity doAnything(String value) throws NoResultException {
try {
Query query = em.createNamedQuery("SomeQuery");
query.setParameter("aParam", value);
return (AnEntity) query.getSingleResult();
} catch (NoResultException nre) {
throw new NoResultException();
}
}
I´m using Container Managed Transaction.
If the query does NOT find "AnEntity" then a NoResultException is thrown, that should be catched by XBean.
But this is not the case. Instead, the Transaction is rolled back and a TransactionRolledbackLocalException is thrown:
[#|2008-01-15T20:30:15.265+0100|INFO|sun-appserver9.1|javax.enterprise.system.container.ejb|_ThreadID=18;_ThreadName=httpSSLWorkerThread-8080-0;YBean;|EJB5018: An exception was thrown during an ejb invocation on [YBean]|#]
[#|2008-01-15T20:30:15.265+0100|INFO|sun-appserver9.1|javax.enterprise.system.container.ejb|_ThreadID=18;_ThreadName=httpSSLWorkerThread-8080-0;|
javax.ejb.TransactionRolledbackLocalException: Exception thrown from bean; nested exception is: javax.persistence.NoResultException
javax.persistence.NoResultException
"Catched NoResultException!" is never printed in the system log!
---------------------
This behavior is not intended.
JAVA EE 5 Javadoc explains NoResultException as follows:
"Thrown by the persistence provider when getSingleResult() is executed on a query and there is no result to return. This exception will NOT cause the current transaction, if one is active, to be marked for roll back."
----------------------
Can anybody tell me if this is a bug or if I´m doing something completely wrong?!
----------------------
The problem does not occure if i add the following entry to the "ejb-jar.xml":
<assembly-descriptor>
<application-exception>
<exception-class>javax.persistence.NoResultException</exception-class>
<rollback>false</rollback>
</application-exception>
</assembly-descriptor>
But this entry SHOULD NOT be necessary.
-------------------
What´s wrong here?
[Message sent by forum member 'zebhed' (zebhed)]
http://forums.java.net/jive/thread.jspa?messageID=254057