dcsimg
Primary keys for entity beans with Bean Managed Persistence
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Ajit_Gopalan
Posted On:   Thursday, March 4, 2004 12:41 AM

The bean-managed persistence mechanism for entity beans imposes that each entity bean has a primary key which is to be used for uniquely identifying data to be loaded from the persistent storage. This primary key will so have to be unique for each BEAN INSTANCE. Also since ejb are not multithreaded , the application server when faced with the issue of concurrent requests generates multiple bean instances.Hence multiple bean instances can exist at runtime, which represent the same underlying data. However in such a situation , wont multiple bean instances have the same primary key ?????????????    More>>

The bean-managed persistence mechanism for entity beans
imposes that each entity bean has a primary key which
is to be used for uniquely identifying data to be loaded from the persistent storage.

This primary key will so have to be unique for each BEAN INSTANCE.


Also since ejb are not multithreaded , the application
server when faced with the issue of concurrent requests
generates multiple bean instances.Hence multiple bean
instances can exist at runtime, which represent the
same underlying data.

However in such a situation , wont multiple bean instances have the same primary key ?????????????

   <<Less

Re: Primary keys for entity beans with Bean Managed Persistence

Posted By:   Srivatsa_Manjunath  
Posted On:   Thursday, March 4, 2004 07:51 AM

Typically I would use a sequence such as oracle sequence to generated unique Primary keys during database insert time. So mmultiple inserts do not create duplicates at runtime and the BMP need not set the PK since the database sequence takes care of setting the value.



Also its a good idea to set database level constraints to take care of concurrency to be on the safter side.


You could also try to use BMP with CMT (container managed transactions) with exclusive or pessimistic locking if your data integrity is such a constraint.
About | Sitemap | Contact