问题
Is it possible to set the database isolation level (ie Serializable, repeatable-read etc) for a given EJB 3 method call?
I understand that this is not covered by the EJB Spec, so details of how to do it on either a JBoss or Glassfish specific manner would be great.
I'm starting to get the impression it's not possible and that you can only set it per Connection Pool which is clearly by no means an ideal solution.
回答1:
This is indeed not covered by the spec and but can be configured through application server specific deployment descriptors when supported. WebLogic does for example and you can specify transaction isolation at the method level in the weblogic-ejb-jar.xml:
Example
<transaction-isolation> <isolation-level>...</isolation-level> <method> <description>...</description> <ejb-name>...</ejb-name> <method-intf>...</method-intf> <method-name>...</method-name> <method-params>...</method-params> </method> </transaction-isolation>
I don't know if JBoss or GlassFish have an equivalent (I couldn't access the SupportWLDDInContainers page to find an answer for GlassFish).
As an alternative, did you try to use Connection#setTransactionIsolation(int) inside a given EJB method using i.e. configuring isolation programmatically?
来源:https://stackoverflow.com/questions/585968/how-can-i-set-isolation-levels-per-method-in-ejb-3