26. Given an excerpt from a stateful session bean:
10. @Stateful
11. public class MyStatefulBean implements MyStateful, SessionSynchronization {
12. @Resource SessionContext ctx;
13. public void afterCompletion(boolean f) {}
14. public void beforeCompletion() { ctx.setRollbackOnly(); }
15. public void afterBegin() {}
16. @Remove
17. public void inc() {}
18. }
The MyStateful interface is a local business interface that declares inc to be a business method. No deployment descriptor is used. A stateless session bean using container-managed transactions has a business method that acts as a client:
20. @TransactionAttribute(TransactionAttributeType.REQUIRED)
21. public String doIt() {
22. ms.inc();
23. }
The method doIt is called without a transactional context. Which order properly reflects the order of method invocation?
1) doIt, afterBegin, inc
2) doIt, inc, afterBegin, beforeCompletion
3) doIt, inc, beforeCompletion, afterBegin, afterCompletion
4) doIt, inc, afterBegin, beforeCompletion, afterCompletion
5) doIt, afterBegin, inc, beforeCompletion, afterCompletion
SCJP 1.4, SCWCD 5, SCBCD 5, OCPJWSD 5,SCEA-1, Started Assignment Part 2
My blog- http://rkydesigns.blogspot.com
[My Blog]
All roads lead to JavaRanch
If the Remove method completes successfully or if the Remove methods throws an application exception for which retainIfException is not true or if a system exception is thrown, SessionSynchronization methods are not called on the bean instance. If an application exception is thrown for which retainIfException is true,the bean is neither destroyed nor discarded, and SessionSynchronization methods, if any, are called on the instance at the end of transaction.
The container must call the afterBegin, beforeCompletion, and afterCompletion methods if the session bean class implements, directly or indirectly, the SessionSynchronization interface. The container does not call these methods if the session bean class does not implement the SessionSynchronization interface
[My Blog]
All roads lead to JavaRanch
[My Blog]
All roads lead to JavaRanch
SCJP 1.4, SCWCD 5, SCBCD 5, OCPJWSD 5,SCEA-1, Started Assignment Part 2
My blog- http://rkydesigns.blogspot.com
SCJP 1.4, SCWCD 5, SCBCD 5, OCPJWSD 5,SCEA-1, Started Assignment Part 2
My blog- http://rkydesigns.blogspot.com
SCJP 1.4, SCWCD 5, SCBCD 5, OCPJWSD 5,SCEA-1, Started Assignment Part 2
My blog- http://rkydesigns.blogspot.com
[My Blog]
All roads lead to JavaRanch
1) Implementing SessionSynchronization methods should not set the @Override annotation. It should not even compile.
2) You're not calling the session bean's remove method
Another thing, how can you use the timer service ? Timers cannot be created for stateful session beans. That's a lot of errors, making me wonder how you could compile and deploy such a class.
SCJP 1.4, SCWCD 5, SCBCD 5, OCPJWSD 5,SCEA-1, Started Assignment Part 2
My blog- http://rkydesigns.blogspot.com
2) I am not calling the session bean's remove method. Isn't this part of bean lifecycle method, so when the container see's @Remove, it call's the code inside it.
Sorry i did hurriedly, so didn't checked out.
[My Blog]
All roads lead to JavaRanch
You don't like waffles? Well, do you like this tiny ad?
The Low Tech Laboratory Movie Kickstarter is LIVE NOW!
https://www.kickstarter.com/projects/paulwheaton/low-tech
|