Skip to main content

@ApplicationException(rollback=true) does not rollback transaction

6 replies [Last post]
robert74
Offline
Joined: 2008-06-18

Hi,

I'm quite new to EJB3. I have simple code which should rollback transaction. (as far as I know)

Issue is that it is not rolling back transaction.

Here is the code:
--------------------------
@ApplicationException(rollback=true)
public class ApplicationFailureException extends Exception {
public ApplicationFailureException() {}
}

------------------------
@Remote({PersonService.class})
@Stateless
public class PersonServiceEjbImpl implements PersonService, Serializable {

@PersistenceContext(unitName = "SeeOneServicesEjbImplPU")
EntityManager em;

public void updatePersonSalary(long personID, long salary) throws ApplicationFailureException {
PersonEntity pe = em.find(PersonEntity.class, Long.valueOf(personID));
pe.setSalary(salary);
throw new ApplicationFailureException();
}
}

I'm working on GF v2ur2 and PersistanceProvider is TopLink.

Any idea why the above code do not roolback transaction.

Thanks
Robert

Message was edited by: robert74

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
cf126330
Offline
Joined: 2005-03-29

How do you know the transaction is not rolled back?

robert74
Offline
Joined: 2008-06-18

Look into database using GUI ...

cf126330
Offline
Joined: 2005-03-29

Hi, Robert,

I just tried an application with the steps you described. I didn't see the problem. That is, the update that is rolled back takes no effect.

On the other side, after changing to rollback=false, I can see the new changes. If you still see the issue, please attach a testcase.

I'm running Sun Java System Application Server 9.1_02, which corresponds to glassfish v2u2.

-cheng

robert74
Offline
Joined: 2008-06-18

Hi Cheng,

Sorry for confusion. I have found the error. I have separated Domain specific stuff in separate JAR package. besides interfaces and DTO's it contains also ApplicationExceptions. UI and Domain logic implementation was depending in this one package. But only Implementation was deployed. When I put ApplicationEception directly into implementation everythink was correct.

Hovever now it is a it unclear to me how the application should be packaged as AppliationException is domain specific and as such it needs to be near interfaces. If interfaces are, together with Exceptions are in separate JAR it seems that only way to declare ApplicationException to be recognized by application server is though deployment descriptor? I have thounght that application server recognizes exception as ApplicationException at throw time. It seems that I was wrong. Application server recognizes ApplicationException at deployment time ... ?

thanks for help

Regards
Robert

cf126330
Offline
Joined: 2005-03-29

EJB packaging is very flexible. You can include all referenced classes via physical inclusion or reference. I would view app exception classes as part of the contract, similar to interfaces. It's a good practice to package them into a sharable jar file, just as you did.

When I packaged my app exception class into EAR/lib/appexception.jar, I got the same tx-not-rollback problem. Essentially the @ApplicationException is ignored and not processed at deployment time. This needs to be corrected. Can you file a bug in glassfish issue tracker (https://glassfish.dev.java.net/servlets/ProjectIssues)?

Another side of this bug is, when you have a unchecked application exception with rollback=false, I guess the current glassfish would incorrectly roll it back.

Thanks,
-cheng

robert74
Offline
Joined: 2008-06-18

Hi Cheng,

Issue is reported. Issue number is 5183.

Thanks again.
Robert