• Post Reply Bookmark Topic Watch Topic
  • New Topic

EJB Transactions in Jboss 3.2.4  RSS feed

 
Sree Nivas
Ranch Hand
Posts: 95
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello All,

I have a problem EJB transactions in Jboss3.2.4. I have two create methods in two EJBs say createABC in FirstEJB and CreateBCD in SecondEJB. These two methods are called one by one in another file say MyFile.java. Presently these two are individual beans both are running in different transaction(i.e container mentioned in ejb-jar.xml). My problem is how do I bring these two beans under one transaction, so that if one create method fails the transaction will be rolled back and the second create method in second bean shouldn't run. Presently even if one create method fail some times the second create method in second bean is success which we don't want as per the requirement.

Any one has any idea about it?
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Configure them to use the same transaction. Assuming you are using CMT use the trans-attribute "Required" - if a transaction doesn't exist one will be created, if it does exists the method will join that transaction.
 
Ec Kjellberg
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think the client needs to explictly get a user-transaction from JNDI and start it before calling any of the two EJBs to be able to hold them in the same transaction (and of course set the trans-attribute to 'required' as mentioned). Alternativly you could create a third EJB (preferably a stateless sessionbean) that calls the other two with the trans-attribute set to 'required').
 
Sree Nivas
Ranch Hand
Posts: 95
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is ok with me if two beans are in the same project. But I forgot to add another thing. These two beans are actually running in two different projects of jboss3.2.4. This is where I'm facing the problem. Can u thro some light on this.

regards
Sreeni
 
Ec Kjellberg
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not quite sure what you mean by 'projects' but I assume that it is two different JBoss instances or something that are running in two different JVM?

I suppose that their could be some ways to get and start an user-transaction remotely by the client so that you could roll back or commit as needed (a little bit depending on the underlaying database also).

But maybe the simple answer would be to avoid that and keep the two EJBs in the same context so that they can share the same (EJB) transaction.
 
Sree Nivas
Ranch Hand
Posts: 95
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Projects I mean in my prev post they are two individual ejb project workspaces created in eclipse. That means I think we have two contexts for two projects.

OK. I'll explain this in detail. We have two versions of products. Say P1 version 1.0 and P2 version 2.0. There is absolutely no problem in P2v2.0 since here beans are developed spring-enabled EJBs. And we have one eclipse workspace project. So we had one application context, hence no issues regading transactions.

But the problem is in older version product i.e P1 v1.0. Here we have individual eclipse workspace projects as I mentioned earlier without usage of springs. So obviously we had individual contexts for every workspace project. And so the beans are in invidual eclipse projects means in individual contexts. Hence the problem arised.

And finally these two products are already sold and hence we cann't user springs in first version now. And this customer presently is not ready to buy the newer version i.e 2.0 product.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!