Skip to main content

@ApplicationException-Annotation not found by container

8 replies [Last post]
shine4u
Offline
Joined: 2010-10-14
Points: 0

Hi,

I recently faced the problem, that a UserException annotated with ApplicationException and rollback=true did not cause a rollback in case it is thrown. After some research I found this issue https://glassfish.dev.java.net/issues/show_bug.cgi?id=5183 the described situation resembles mine.

We have the following structure. There are two ejb-jars. The first one contains the UserException, the second one has a session bean modifies and entity and throws the exception. If tested by calling the session bean from a jsp in a war file, the exception does not cause the transaction to rollback.

By now I have figured out that adding a using a ejb-jar.xml in the second ejb-jar that contains the UserException in its assembly-constructor solves the problem, but still I am wondering if it is intended behaviour that the UserException is not regarded as ApplicationException with rollback true if this .xml-File is absent.

I'm currently working with Glassfish v3.

Thanks for your help.

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
mvatkina
Offline
Joined: 2005-04-04
Points: 0

How do you make sure that BadApplicationException is in the classpath of the second EJB jar?

shine4u
Offline
Joined: 2010-10-14
Points: 0

the class-path in the Manifest.mf-file in META-INF of EjbJar2 includes EjbJar.jar.

mvatkina
Offline
Joined: 2005-04-04
Points: 0

This is kind of dangerous because this means that EJBs from EjbJar are in their own module and part of the EjbJar2. Your best bet would be to have shared interfaces in the lib jar.

-marina

hzhang_jn
Offline
Joined: 2005-07-22
Points: 0

Are these two ejb jars packaged inside an ear? If you package the UserException class directly in the second ejb jar (without using ejb-jar.xml), does it work?

Can you attach the test case?

shine4u
Offline
Joined: 2010-10-14
Points: 0

Yes, the two ejb jars are packaged inside an ear. in the attachment, you can find the sources (from 4 eclipse projects) that represent that structure.
Two ejb jars, EjbJar contains BadApplicationException, EjbJar2 contains GoodApplicationException. Both are annotated with @ApplicationException.

SomeWebBean in EjbJar2 calls getGoodMessage or getBadMessage which throw GoodApplicationException or BadApplicationException respectively. If the ejb-jar.xml is not present only GoodApplicationException causes a rollback, if it is present, both cause the rollback.

Thanks for your help

hzhang_jn
Offline
Joined: 2005-07-22
Points: 0

I see. If the BadApplicationException needs to be used by both EJB jars, you should package the class as a library jar in the ear library directory.

shine4u
Offline
Joined: 2010-10-14
Points: 0

Ok, so if Classes like this ApplicationException with Annotations are used by more EJB jars, such classes should be packaged in the ear lib.
I don't know if this is technically correct, but as far as I understand the situation, the container "scans" only the ear lib and the EJB jar for such annotations like @ApplicationException (and classes explicitly stated in an ejb-jar.xml), even though the BadApplicationException is in the classpath of the second EJB jar and can be used there.

That sounds a bit strange to me, do you know why this is?

hzhang_jn
Offline
Joined: 2005-07-22
Points: 0

The annotations on the classes, just like the declations in the ejb-jar.xml, are deployment medata which are scoped to the declaring jar and not visible to other jars.