[
https://issues.jboss.org/browse/AS7-5530?page=com.atlassian.jira.plugin.s...
]
John Mazzitelli commented on AS7-5530:
--------------------------------------
I was just going to create this very issue. I have a replication war. I took the
quickstart for singleton example, tweeked it, and now when you go to the browser, you get
an error:
"javax.ejb.EJBException: Transaction present on server in Never call (EJB3
13.6.2.6)"
I will attach my war, which again is nothing more than the quickstart with this added to
Counter.java:
@javax.ejb.EJB MyOtherEJB myOtherEjb;
@javax.annotation.PostConstruct
@javax.ejb.TransactionAttribute(javax.ejb.TransactionAttributeType.NOT_SUPPORTED)
public void init() {
System.out.println("!!!!!!!!!!!!!! postconstruct !!!!!!!!!!!!!!");
myOtherEjb.hello();
}
Where MyOtherEJB is:
package org.jboss.as.quickstarts.singleton;
@javax.ejb.Stateless
public class MyOtherEJB {
@javax.ejb.TransactionAttribute(javax.ejb.TransactionAttributeType.NEVER)
public void hello() {
System.out.println("!!!!!!!!!!!!!! MyOtherEJB.hello !!!!!!!!!!!!!!");
}
}
Singletons don't respect @TransactionAttribute/deployment
descriptor in @PostConstruct.
---------------------------------------------------------------------------------------
Key: AS7-5530
URL:
https://issues.jboss.org/browse/AS7-5530
Project: Application Server 7
Issue Type: Bug
Components: EJB
Affects Versions: 7.1.1.Final
Environment: JBoss 7.1.1
Reporter: Sławomir Wojtasiak
Assignee: jaikiran pai
Priority: Minor
Labels: rhq
Attachments: jboss-as-helloworld-singleton.war
Singletons don't respect any transaction attributes for their @PostConstruct methods
and invokes them always with REQUIRED_NEW semantics. Following part of code is responsible
for hardcoding these values for registered _SingletonLifecycleCMTTxInterceptor_
factories:
{code:title=org.jboss.as.ejb3.component.singleton.SingletonComponentDescription.java|borderStyle=solid}
@Override
public void configure(final DeploymentPhaseContext context, final
ComponentDescription description, final ComponentConfiguration configuration) throws
DeploymentUnitProcessingException {
configuration.addPostConstructInterceptor(new
SingletonLifecycleCMTTxInterceptor.Factory(TransactionAttributeType.REQUIRES_NEW),
InterceptorOrder.ComponentPostConstruct.TRANSACTION_INTERCEPTOR);
configuration.addPreDestroyInterceptor(new
SingletonLifecycleCMTTxInterceptor.Factory(TransactionAttributeType.REQUIRES_NEW),
InterceptorOrder.ComponentPreDestroy.TRANSACTION_INTERCEPTOR);
if(description.isPassivationApplicable()) {
configuration.addPrePassivateInterceptor(new
SingletonLifecycleCMTTxInterceptor.Factory(TransactionAttributeType.REQUIRES_NEW),
InterceptorOrder.ComponentPassivation.TRANSACTION_INTERCEPTOR);
configuration.addPostActivateInterceptor(new
SingletonLifecycleCMTTxInterceptor.Factory(TransactionAttributeType.REQUIRES_NEW),
InterceptorOrder.ComponentPassivation.TRANSACTION_INTERCEPTOR);
}
configuration.addTimeoutViewInterceptor(TimerCMTTxInterceptor.FACTORY,
InterceptorOrder.View.CMT_TRANSACTION_INTERCEPTOR);
}
{code}
EJB 3.1 specification says, REQUIRED, REQUIRED_NEW and NOT_SUPPORTED attributes should be
supported, where in case of REQUIRED a semantic of REQUIRED_NEW trancation attribute
should be used:
{panel:title=4.8.3 Transaction Semantics of Initialization and Destruction|
borderStyle=dashed| borderColor=#ccc| titleBGColor=#F7D6C1| bgColor=#FFFFCE}
PostConstruct and PreDestroy methods of Singletons with container-managed transactions
are transactional. From the bean developer’s view there is no client of a PostConstruct or
PreDestroy method.
A PostConstruct or PreDestroy method of a Singleton with container-managed transactions
has transaction attribute REQUIRED, REQUIRES_NEW, or NOT_SUPPORTED (Required ,
RequiresNew, or NotSupported if the deployment descriptor is used to specify the
transaction attribute).
_Note that the container must start a new transaction if the REQUIRED (Required)
transaction attribute is used. This guarantees, for example, that the transactional
behavior of the PostConstruct method is the same regardless of whether it is initialized
eagerly at container startup time or as a side effect of a first client invocation on the
Singleton. The REQUIRED transaction attribute value is allowed so that specification of a
transaction attribute for the Singleton PostConstruct/PreDestroy methods can be
defaulted._
{panel}
So there is not a problem with REQUIRED and REQUIRED_NEW transaction attributes, but
NOT_SUPPORTED attribute is just not supported :)
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see:
http://www.atlassian.com/software/jira