Thanks & Regards, SK
SCJP 5.0, DB2 - 800, DB2 - 803, SCDJWS (On the way)
Schandha Ravi wrote:Can I synchronize the code using block synchronization in session bean, where the entity beans are persisted around the primary key generation and persistance of the entity bean.
Schandha Ravi wrote:I was proposing to query the table to determine the latest primary key and increment it just like trigger doing and use that new primary key to persist the next entity. But there was a question concerning the following of ACID properties here. How can we ensure that before a new key is identified and assigned, there was not another request for peristing another entity and we mix up the keys.
SCJP 5 (98%) - SCBCD 5 (98%)
Schandha Ravi wrote:
Can I synchronize the code using block synchronization in session bean, where the entity beans are persisted around the primary key generation and persistance of the entity bean.
No, an ejb must not use thread synchronization (except it's an EJB3.1-singleton bean with bean-managed concurrency).
Thanks & Regards, SK
SCJP 5.0, DB2 - 800, DB2 - 803, SCDJWS (On the way)
That's a programming restriction due to the ejb spec (see for example EJB 3.1 spec, section 21.2.2). If you are using your own thread handling in a session or mesage driven bean then the behavoir of the system is undefined.Schandha Ravi wrote:Why the thread synchronization not permitted in an ejb. I'm sure it would not throw me any compiler errors. But what potential problems could we face, if used. Would this intervene with container and result into undesirable situation.
It's not allowed in general, but only for the newly introduced singleton beans:Schandha Ravi wrote:What changes came in for allowing this in EJB3.1
If getPrimaryKey returns the generated key in ejbPostCreate then this should be manageable.Schandha Ravi wrote:Since, all I needed was to send back the right primary key to the calling application, can't I try retrieving it in ejbPostCreate().
SCJP 5 (98%) - SCBCD 5 (98%)
Thanks & Regards, SK
SCJP 5.0, DB2 - 800, DB2 - 803, SCDJWS (On the way)
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime. |