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?
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
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
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.
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