Advertisement

05.20.2008 at 04:40AM PDT, ID: 23416696
[x]
Attachment Details

How to manage method-scoped transactions in EJB 3.0

Asked by summerian in Enterprise Java Beans (EJB), J2EE

Tags: Java, EJB, JBoss

Hi

I'm using stateless EJB 3 with JBoss 4.2.2GA as app server.

I have problem with isolating transactions on desired methods. I have two EJB methods, one is calling the other in a loop. The first method (outer) call lasts for a long time, which cause transaction to timeout and cause transaction error. The second (inner) method requires transaction.

Now, I know that I can extends transaction time to longer period, but I want to try another way. I want the outer method to not have transaction, but would like the inner method to create transaction if it does not exist. How do I do that? Is that possible?

I tried TransactionAttributeType.SUPPORTS or TransactionAttributeType.NEVER on the outer method, but the transaction would not be created for the inner method either.

Example explanation is below
Start Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
@Stateless(name="MyEJB")
@LocalBinding(jndiBinding="ejb/MyEJB/local")
@RemoteBinding(jndiBinding="ejb/MyEJB/remote")
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public class MyEJB {
 
   //I don't want transaction here
   //these annotations turn off transaction on inner method also
   //@TransactionAttribute(TransactionAttributeType.SUPPORTS)
   //@TransactionAttribute(TransactionAttributeType.NEVER)
   public void methodOuter(){
      MyEJB2 myEjb2;//get EJB2
 
      for(/*some conditions*/){
          //...
          myEjb2.methodInner();
      }
   }
}
 
@Stateless(name="MyEJB2")
@LocalBinding(jndiBinding="ejb/MyEJB2/local")
@RemoteBinding(jndiBinding="ejb/MyEJB2/remote")
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public class MyEJB2 {
 
   //I need transaction here
   public void methodInner(){
      
   }
}
 
Loading Advertisement...
 
[+][-]05.22.2008 at 11:52AM PDT, ID: 21626527

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.23.2008 at 08:27AM PDT, ID: 21633007

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]05.28.2008 at 05:15AM PDT, ID: 21659659

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]05.28.2008 at 07:36AM PDT, ID: 21660777

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: Enterprise Java Beans (EJB), J2EE
Tags: Java, EJB, JBoss
Sign Up Now!
Solution Provided By: filosof
Participating Experts: 1
Solution Grade: A
 
 
[+][-]08.21.2008 at 09:42AM PDT, ID: 22281426

Experts Exchange has a courteous staff of administrators who help members get the most out of the website by means of administrative comments like this one.

Start your 7-day free trial to view this Administrative Comment or ask the Experts your question.

 
[+][-]08.27.2008 at 09:01PM PDT, ID: 22331431

Experts Exchange has a courteous staff of administrators who help members get the most out of the website by means of administrative comments like this one.

Start your 7-day free trial to view this Administrative Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628