javaee / ejb-spec

See javax.ejb project for API. Contains legacy issues only.
https://github.com/javaee/javax.ejb
6 stars 1 forks source link

Clarify behaviour for setRollbackOnly() #90

Open glassfishrobot opened 11 years ago

glassfishrobot commented 11 years ago

in my opinion JSR-345 9.3.9 Exceptions from the Management of Container-Managed Transactions could benefit by adding clarification(s). "This subsection specifies how the container must deal with the exceptions that may be thrown by the transaction start and commit operations." reading this section suggests, that TX will reach commit point, which is not true in all cases, for example

Bean_method(){
  Code_Block_A (prepare some data)
  write_data_to_DB (e.g. JPA)
  Code_Block_B (prepare data for legacy backend)
  write_to_legacy_backend_using_3rd_party_code()
  Code_Block_C (do some checks)
}

I've tested this with GFv3 and I find it disturbing, that the behaviour changes, depending where the setRollbackOnly() is called a) if set in block_a, then an Excetpion is thrown before write_data_to_db. in the GF case it comes from JTA-subsystem during enlist resource b) if set in block_c, then no excption is thrown

one could argument, that "if you setRollbackOnly, then you must also throw an ApplicationException", but what if setRollbackOnly is us in 3rd party code, such as write_to_legacy_backend_using_3rd_party_code? legacy-code comes back without exception, setRollbackOnly==true, block_c runs without excpetion, TX rollsback without exeception.

In my opinion the spec is not conclusive on this matter. I'd prefer to have a consistent behaviour no matter where setRollbackOnly is used. (either throw Exception or don't throw exception) I think it would be easier to understand if containers would follow the description from 9.3.9 "However, the container should not throw the javax.ejb.EJBException or java.rmi.RemoteException if the container performs a transaction rollback because the transaction has been marked for rollback and no EJBException or RemoteException would otherwise be thrown according to sections [9.3.1] through [9.3.8]."

Affected Versions

[3.2]

glassfishrobot commented 11 years ago

Reported by schaarsc

glassfishrobot commented 11 years ago

mvatkina said: Suppressing exceptions can lead to an incompatible behavior. We will look at adding an option to throw an exception on rollback in the next version of the spec.

glassfishrobot commented 11 years ago

Was assigned to mvatkina

glassfishrobot commented 7 years ago

This issue was imported from java.net JIRA EJB_SPEC-90