You can try checking the Connection autoCommit checkbox to see if it is in the transaction (regardless of where it came from). Strike> (Apparently, see the accepted answer, this does not work too well. I do not delete this answer because the following remains :)
But I think that you really need to change your API so that it depends only on external transactions. If you still want to support simple JDBC, wrap it in a separate API that is just starting the transaction.
Update. Just re-read your question and make sure you are not providing an API, but want to use a container-driven connection. But still, can you simply instruct (as part of your application requirements) that the JTA will act? If not, you can provide a configuration option to revert to manual transactions. For such a critical function, it seems reasonable to require the correct configuration (as opposed to trying to guess what would be appropriate).
source share