aspose file tools*
The moose likes EJB Certification (SCBCD/OCPJBCD) and the fly likes Transaction across methods in Entity Beans? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » EJB Certification (SCBCD/OCPJBCD)
Bookmark "Transaction across methods in Entity Beans?" Watch "Transaction across methods in Entity Beans?" New topic
Author

Transaction across methods in Entity Beans?

Vishwa Kumba
Ranch Hand

Joined: Aug 27, 2003
Posts: 1066
From the spec, I understand that in stateless/message-driven beans, the transaction starts/ends in the same method.In a stateful session bean the transaction may start in one method and end in another method.
What about entity beans? Can my transaction start and end in different methods?
Rishi Singh
Ranch Hand

Joined: Dec 09, 2000
Posts: 321
Hi Vish,
The very notion of a transaction doed not hold good for a Entity Bean bcoz the Entity Beans are suppose to represent domain objects or more precisely
rows in database tables. In a case if there is a requirement of domain biz logic wherein you need to start a transaction it should be BMP Entity Beans
and offcourse since the container maintains a pool of entity bean instances which implies that it can be assigned to any client or it can be swapped in its POOLED state which further implies it acts like stateless. So the transaction cant be forwaded to another method.It needs to end in a single method.
Rishi
SCJP,SCWCD,IBM OOAD
Sivasundaram Umapathy
Ranch Hand

Joined: Aug 10, 2002
Posts: 360
Entity Beans must use Container Managed Transactions and there is no possibility of starting and ending in different methods


Siva
Co-Author - SCMAD Exam Guide - ISBN:9780070077881
Author - Java certification success, Part 4: SCEA
Vishwa Kumba
Ranch Hand

Joined: Aug 27, 2003
Posts: 1066
Thanks guys!....
I couldn't grasp this from the spec.
Andrew Monkhouse
author and jackaroo
Marshal Commander

Joined: Mar 28, 2003
Posts: 11509
    
  95

Hi Guys,
While agreeing that transactions are not something an entity bean programmer has to worry about, I don't think I can agree that they don't exist.
Section 14.2.3 of the specification shows how passivation and activation of an entity bean occurs while in a transaction. So entity beans can be used within transactions, and do have state.
Which makes sense, otherwise we could not have the concept of rollback on an entity bean.
Sivasundaram is correct with his statement that entity beans must have container managed transactions (section 17.3.1). The second part of his statement I am not so sure about (because I am pedantic).
Since you cannot progamatically start a transaction from within an entity bean's method, logically you cannot end it in a different method. But since a transaction could be started from within a session bean or from the client itself, it is quite possible that two different methods of the entity bean could be called from within the same transaction.
Regards, Andrew


The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
Sivasundaram Umapathy
Ranch Hand

Joined: Aug 10, 2002
Posts: 360
Andrew,may be i can convince you by referring the life cycle diagrams of entity,SLSB,SFSB.If you see in entity and SLSB,you can can find after the invocation of a method,the bean returns to the method-ready state where as it is different in the case of SFSB.
Andrew Monkhouse
author and jackaroo
Marshal Commander

Joined: Mar 28, 2003
Posts: 11509
    
  95

Hi Sivasundaram,
I am not sure if I have argued a different point to you. You are correct that a transaction cannot be started in one method of an entity bean and completed in another method.
My comment was tangental to that: two separate methods of an entity bean can be called from within a transaction started by some other bean.
Regards, Andrew
 
jQuery in Action, 2nd edition
 
subject: Transaction across methods in Entity Beans?