Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Contradiction in the javadoc of UserTransaction and @Transactional #68

Open
glassfishrobot opened this issue Jan 25, 2017 · 6 comments
Open

Comments

@glassfishrobot
Copy link

There is a contradiction in the JTA spec:

1. On one hand, the UserTransaction javadoc [1] states that if the thread is already associated with a transaction and the Transaction Manager implementation does not support nested transactions, a NotSupportedException will be thrown.

2. On the other hand, the javadoc of the Transactional annotation [2] states that if an attempt is made to call any method of the UserTransaction interface from within the scope of a bean or method annotated with @transactional and a Transactional.TxType other than NOT_SUPPORTED or NEVER, an IllegalStateException must be thrown

So if I have a method annotated with @transactional(TxType.REQUIRED) and within it I call userTransaction.begin(), then what should be the expected exception - IllegalStateException or NotSupportedException ?

[1] http://docs.oracle.com/javaee/7/api/javax/transaction/UserTransaction.html#begin--

[2] http://docs.oracle.com/javaee/7/api/javax/transaction/Transactional.html

@glassfishrobot
Copy link
Author

@glassfishrobot Commented
Reported by SvetlinZarev

@glassfishrobot
Copy link
Author

@glassfishrobot Commented
Was assigned to paul_parkinson

@glassfishrobot
Copy link
Author

@glassfishrobot Commented
ldemichiel said:
I believe the intent here is that it is always an error to try to access any method of the UserTransaction interface when a bean is marked as using container-managed transactional demarcation as specified by the Transactional annotation, and to treat this error uniformly. I don't see this as a contradiction with regard to the rule that UserTransaction.begin must not be invoked when a transaction is in progress, but rather that the rules around @transactional take precedence / are applied first.

@glassfishrobot
Copy link
Author

@glassfishrobot Commented
svetlinzarev said:
It makes sense now. Just to confirm my understanding: It's meant that calling any method on UserTransaction from application code is forbidden when using CMT demarcation (regardless of whether nested transactions are supported), thus any such calls should result in IllegalStateException being thrown by the called method. Hence in the case described in the ticket description, userTransaction.begin() must throw IllegalStateException:

@Transactional(TxType.REQUIRED)
    public void testTxTypeRequired() {
        userTransaction.begin(); //Will throw IllegalStateException
        //do stuff
        userTransaction.commit();
    }

In that case it might be good idea to enhance the javadoc of UserTransaction, in order to make its contract unambiguous that its methods may throw IllegalStateException.

@glassfishrobot
Copy link
Author

@glassfishrobot Commented
This issue was imported from java.net JIRA JTA_SPEC-14

@glassfishrobot
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant