Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Why Entity beans are always CMT

 
Kartik Patel
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I went thru spec and many other resources to find that why entity bean should always run in container managed transaction.???

But i only got answer that it should be because its written in the spec...
but can someone tell me valid reason of having just CMT for entity bean..

Session bean can run in both BMT and CMT...


So why not entity bean???
 
Shrinivas Mujumdar
Ranch Hand
Posts: 328
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey Kartik,
Entity beans(CMP & BMP) provides objectified representation of data in underlying datastore, they are always transactional meaning,whenever you invoke any method on them its always executed within Transaction.
Main idea of having entity bean is DATA PERSISTANCE & DATA MANIPULATION through java objects, hiding the complexity of DB Operations like queries,Transactions etc...
Session Beans however are transaction aware, they represent process / workflow.

I hope this helps, otherwise Ping Javaranch one more time.

I would suggest Read Topic from Oreilly(Richard Manson) & Head First EJB

Shrinivas Mujumdar

 
Kartik Patel
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey Shrini,
Thanks for prompt reply.. I got ur point that entity beans are only meant for Transactional processes... and in session bean u can have transactional process as well as non-transactional processes...

but even though my question remain same... if transaction are associated with the entitt beans than why cant we use BMT???

So we can reduce the scope of the transaction
if Sun doesn't want to disturb the lifecycle of entity bean than it could have given BMT entity bean with restriction that one can reduce the scope of transaction but cant expand it to more than 1 method....So its like special kind of bean managed transaction...



Rather it would be a good idea to provide this extra feature to enity bean as the are always involved with transaction.... and sometimes u just want a part of the method to be in transaction .. not just the whole method... and sometimes u want to put more than one transaction in just 1 method... so in this case BMT entity bean could be a good idea...

but Why does SUN Microsys. not provided this feature of BMT in entity bean...??
 
Nadeem Awad
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Kartik Patel:
but can someone tell me valid reason of having just CMT for entity bean..


Dear Kartik,
The purpose of the entity bean is to represent some data on the persistence store, provided that the container is responsible for synchronizing the entity instance's state with that store. for example, if a client is calling a business method on the entity bean, the container calls ejbLoad() before the execution of the method, and calls ejbStore() after the method execution has finished and before the transaction is commited. So, If you want the entity bean to be BMT, then you should handle the entity's state synchronization by calling ejbLoad() and ejbStore() along with transaction control statements (i.e. begin, commit). In that case, you are defeating one of the major services that the EJB container provides and entity beans exist for, which is providing a simple OO view of some entities stored in the persistent storage. That said, if you need to implement these services yourself, then you sould consider writing a POJO to access the persistence store.

Best regards,
[ December 14, 2005: Message edited by: Nadeem Awad ]
 
Valentin Tanase
Ranch Hand
Posts: 704
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Kartik,

This thread might clarify your doubts even further.

http://www.coderanch.com/t/317305/EJB-JEE/java/why-entity-bean-cannot-manage

Regards.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic