aspose file tools*
The moose likes EJB and other Java EE Technologies and the fly likes Instance of a CMP ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "Instance of a CMP ?" Watch "Instance of a CMP ?" New topic
Author

Instance of a CMP ?

Shivaji Bhosale
Ranch Hand

Joined: Mar 12, 2001
Posts: 70
For a CMP, a row in a table is represented by CMP instance.
Can it be there more than one CMP instance for a same row in database ?
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16014
    
  20

Somebody recently asked that here somewhere, but I can't find it.
Technically, yes - an EJB is a data entity in its own right, and nothing in the spec actually REQUIRES that it be connected with a database (though Entity Beans do require SOME type of persistent storage to be fully functional).
Practically, I don't recommend it, since one of the reasons why you'd want to use an EJB is to better maintain the integrity of the database by using EJB's ACID properties. If 2 different EJBs represented the same table row and they had overlapping fields, there's a good change the DBMS could be corrupted and/or the EJB runtime environment would display inconsistent data.


Customer surveys are for companies who didn't pay proper attention to begin with.
Shivaji Bhosale
Ranch Hand

Joined: Mar 12, 2001
Posts: 70
Hi Tim,
You are right. My real problem is, 2 concurrent transactions acting on a CMP, which imply same row.
When the 2nd Txn tries to commit the data modified by that Txn, at the point of commit an exception is thrown.
To workaround I caught exception thrown at this commiting point & again tried to commit it in a loop. This soln works. But is not the proper way to do it.
Do u have any suggestions ?
Dharmesh Chheda
Ranch Hand

Joined: May 08, 2001
Posts: 204
Hello Shivaji
Mandating that each bean can service only one client at a time could result in bottlenecks. To boost the performance, we could allow the containers to instantiate multiple instances of the same entity bean class. This would allow many clients to concurrently interact with seperate instances, each representing the same underlying entity data. This may lead to data corruption .. ( THATS WHAT YOU ARE FACING ) .
To achieve entity bean instance cache consistency, each entity bean instance needs to be routinely synchronized with the underlying storage.The container synchronizes the bean with the underlying storage by calling the beans ejbLoad() and ejbStore() callbacks.
The frequency with which beans are synchronized with the underlying storage is dictated with transactions
Transactions allow each client request to be isolated from every other request.They enable clients to believe they are dealing with a single in-memory bean when infact many instances are behind the scenes.Transactions give clients the illusion that they are the only ones accessing the underlying data when infact many clients are touching the same data.
I hope you got it ... use Transactions.


regards,<br />Dharmesh Chheda
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Instance of a CMP ?