File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes EJB Certification (SCBCD/OCPJBCD) and the fly likes Entity beans CMP demarcation... 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 "Entity beans CMP demarcation..." Watch "Entity beans CMP demarcation..." New topic

Entity beans CMP demarcation...

James Turner
Ranch Hand

Joined: May 10, 2004
Posts: 194
Hi Guys,

I found this in the EJB spec:

For CMP entity beans, only the Required, RequiresNew, or Mandatory transaction attributes should be used for the transactional methods defined in the bean's component and home interface.

I am not really sure why this is so, I mean what is wrong with using NotSupported, Supports or Never? If I have my own business methods in an entity bean that I don't want to be in a transaction how could I do this?

Granted, with an entity bean mapped to a persistent store, I would most likely need to execute inside a transaction, but what if I didn't?

Anyone who had any ideas about this please help!


[ November 09, 2004: Message edited by: James Turner ]

James<br />SCJP 1.4 - 92%<br />SCJD - 93%<br />SCWCD 1.4 - 95%<br />SCBCD 1.3 - 100%<br />SCEA - 92%
Arun Krishnamoorthy

Joined: Nov 03, 2004
Posts: 22
The reason you cannot use the other three transaction attributes viz., Supports, Not Supported and Never is because entity beans are always transactional i.e. they have a meaningful transaction context. The other three transaction attributes allow (or enforce) the entity bean's method to run under an unspecified transaction context.

The reason why entity beans are always transactional is because they model shared, persistent business data (and methods that act on the business data). Since they (as in-memory objects) represent persistent data, they need to synchronize themselves with a persistent data store through calls to ejbLoad() and ejbStore(). The use of the ejbLoad and ejbStore methods for caching an entity object´┐Żs state (which is what an entity bean does) in the instance works well only if the Container can use transaction boundaries to drive the ejbLoad and ejbStore
methods. When one of the three attributes specified above is assigned to a remote interface or a home business method, the corresponding
enterprise bean class method executes with an unspecified transaction context. This means that the Container does not have any well-defined transaction boundaries to drive the ejbLoad and ejbStore methods on the instance.

Therefore, the ejbLoad and ejbStore methods become unreliable under the above scenario. This would result in a condition where the entity bean's in-memory state does not match the persistent data state which is highly undesirable.

Hope this helps...
James Turner
Ranch Hand

Joined: May 10, 2004
Posts: 194
Thank you for the response...

That helped a lot.


I agree. Here's the link:
subject: Entity beans CMP demarcation...
It's not a secret anymore!