Friday, March 13, 2009

Is there any way to read values from an entity bean without locking it for

Question :Is there any way to read values from an entity bean without locking it for
the rest of the transaction (e.g. read-only transactions)? We have a keyvalue
map bean which deadlocks during some concurrent reads. Isolation
levels seem to affect the database only, and we need to work within a
transaction. (EJB)

Answer :The only thing that comes to (my) mind is that you could write a 'group
accessor' - a method that returns a single object containing all of your
entity bean's attributes (or all interesting attributes). This method could
then be placed in a 'Requires New' transaction. This way, the current
transaction would be suspended for the duration of the call to the entity
bean and the entity bean's fetch/operate/commit cycle will be in a separate
transaction and any locks should be released immediately. Depending on
the granularity of what you need to pull out of the map, the group accessor
might be overkill.

No comments: