users@javaee-spec.java.net

[javaee-spec users] Re: [jsr342-experts] Re: transactional interceptors and lifecycle methods

From: Yoon Kyung Koo <kyungkoo_yoon_at_tmax.co.kr>
Date: Fri, 15 Mar 2013 19:03:52 +0900

I'm also in favor of #1.
Should life cycle methods be treated as if they were business methods?
It's a little confusing to me.

-- 
--------------------
 Software Innovation Driver
 Researcher & Executive Director / WAS Lab / TmaxSoft R&D Center
 PGP  http://www.javadom.com/personal/yoonforhatgmaildotcom.asc
2013. 3. 15.,  3:43, michael keith <michael.keith_at_oracle.com> ۼ:
> 
> I may be tainted by the past, but interceptors were initially defined to apply to EJB business methods, i.e. methods that were invoked by clients. Life cycle methods obviously don't fall into that category and tend not to need to be intercepted. It is certainly the case that they have not traditionally needed transactions, and arguably seldom will, so setting the default to create a transaction to execute what is typically non-transactional logic is clearly going to be less than optimal. Dunno, but to me #1 looks like the most natural and reasonable option, and I don;t see it as hard to understand at all when the definition of interception is based on non-system method invocations. Like I said, though, my historical baggage could be affecting my vision.
> 
> On 13/03/2013 6:29 PM, Bill Shannon wrote:
>> I really would like to get feedback from more expert group members.
>> 
>> "I don't know" and "I don't care" are acceptable responses.
>> 
>> Bill Shannon wrote on 03/11/13 10:35:
>>> We recently discovered an issue with the interaction between the
>>> new @Transactional interceptors and the @PostConstruct method.
>>> Should @PostContruct (and @PreDestroy) methods be transactional,
>>> and if so how should the transaction type be controlled?
>>> 
>>> We'd like your feedback on this issue before Friday, March 15.
>>> 
>>> We've come up with four options for how this could work:
>>> 
>>> 1. @PostConstruct is not transactional by default, but @Transactional
>>>    is allowed.
>>> 
>>> 	@Transactional(MANDATORY)
>>> 	public class MyBean {
>>> 	    @PostConstruct
>>> 	    public void postConstruct() {
>>> 		// run with no transaction
>>> 	    }
>>> 
>>> 	    public void myMethod() {
>>> 		// uses @Transactional(MANDATORY)
>>> 	    }
>>> 	}
>>> 
>>> 	@Transactional(MANDATORY)
>>> 	public class MyOtherBean {
>>> 	    @PostConstruct
>>> 	    @Transactional(REQUIRES_NEW)
>>> 	    public void postConstruct() {
>>> 		// run with a new transaction
>>> 	    }
>>> 
>>> 	    public void myMethod() {
>>> 		// uses @Transactional(MANDATORY)
>>> 	    }
>>> 	}
>>> 
>>> 2. @PostConstruct is like any other method and inherits the class-level
>>>    transaction attribute, but the developer must override the class-level
>>>    attribute in some cases.
>>> 
>>> 	@Transactional(MANDATORY)
>>> 	public class MyBean {
>>> 	    @PostConstruct
>>> 	    public void postConstruct() {
>>> 		// FAILS because there can be no existing transaction context
>>> 	    }
>>> 
>>> 	    public void myMethod() {
>>> 		// uses @Transactional(MANDATORY)
>>> 	    }
>>> 	}
>>> 
>>> 	@Transactional(MANDATORY)
>>> 	public class MyOtherBean {
>>> 	    @PostConstruct
>>> 	    @Transactional(REQUIRES_NEW)
>>> 	    public void postConstruct() {
>>> 		// run with a new transaction
>>> 	    }
>>> 
>>> 	    public void myMethod() {
>>> 		// uses @Transactional(MANDATORY)
>>> 	    }
>>> 	}
>>> 
>>> 3. @PostConstruct is like any other method and inherits the class-level
>>>    transaction attribute, but methods (like lifecycle callbacks) for
>>>    which there can be no preexisting transaction context are handled as
>>>    if they were REQUIRES_NEW when the MANDATORY attribute is specified
>>>    (i.e., the attribute value handling here is special-cased).
>>> 
>>> 	@Transactional(MANDATORY)
>>> 	public class MyBean {
>>> 	    @PostConstruct
>>> 	    public void postConstruct() {
>>> 		// runs with a new transaction
>>> 	    }
>>> 
>>> 	    public void myMethod() {
>>> 		// uses @Transactional(MANDATORY)
>>> 	    }
>>> 	}
>>> 
>>> 	@Transactional(MANDATORY)
>>> 	public class MyOtherBean {
>>> 	    @PostConstruct
>>> 	    @Transactional(REQUIRES_NEW)
>>> 	    public void postConstruct() {
>>> 		// run with a new transaction, same as above
>>> 	    }
>>> 
>>> 	    public void myMethod() {
>>> 		// uses @Transactional(MANDATORY)
>>> 	    }
>>> 	}
>>> 
>>> 4. @PostConstruct can never be transactional.  UserTransaction can be
>>>    used explicitly in the @PostConstruct method if needed.
>>> 
>>> 	@Transactional(MANDATORY)
>>> 	public class MyBean {
>>> 	    @PostConstruct
>>> 	    public void postConstruct() {
>>> 		// runs with no transaction context
>>> 	    }
>>> 
>>> 	    public void myMethod() {
>>> 		// uses @Transactional(MANDATORY)
>>> 	    }
>>> 	}
>>> 
>>> 	@Transactional(MANDATORY)
>>> 	public class MyOtherBean {
>>> 	    @PostConstruct
>>> 	    @Transactional(REQUIRES_NEW)
>>> 	    public void postConstruct() {
>>> 		// @Transactional is either ignored or causes runtime failure
>>> 	    }
>>> 
>>> 	    public void myMethod() {
>>> 		// uses @Transactional(MANDATORY)
>>> 	    }
>>> 	}
>>> 
>>> 
>>> #1 is most similar to stateful session beans in the current version of
>>> the EJB spec.  When the ability to have transactional @PostConstruct
>>> methods on stateful session beans was added to the EJB spec, it
>>> couldn't be done by default due to compatibility.
>>> 
>>> #3 is consistent with Singletons in the current version of the EJB spec.
>>> 
>>> #4 is most similar to previous versions of the EJB spec.
>>> 
>>> We're currently leaning towards #3, since it seems consistent with other
>>> interceptor use, but good arguments can be made for any of these choices.
>>> We really need your feedback.
>>> 
>>> Let us know which choice you prefer before Friday, March 15.
>>> 
>>> Thanks.
>> 
>> 
>