Janne,

Where are the transations delimited? I assume from your earlier post
that doSomethingWith(artist) is not in it's own transaction. Likewise
doSomethingWith(record) is also not in it's own transaction. Is the
transaction the entire iteration over all artists or just one artist's
records? In either case you're bound to have transaction deadlocks.

If you're not changing the relationship between artist and record why do
you need updates to artist and record in the same transaction?

--Victor


Janne Mattila wrote:


Hi,

currently I run into this problem while running a load test which generates
a bit unrealistic situations. I still think this problem could occur
frequently enough with normal use, too. The example consists of two beans,
Record and Artist with n:1 relationship between them. Application has quite
a lot of different view pages, displaying several combinations of data (all
records with artists / one record & it's artist / one artist & his records
/ etc etc.). At least with the server in question (WebLogic) the order
which you touch the beans determines the order which they are updated at
the end of transaction. Basically to prevent deadlocks I have to make sure:

- beans are always accessed in the same order, for example 1) artist 2)
record. A bit of unconvenience, for example when all artists are listed
with their records. "Normal" use would be

 Iterator i = artistHome.findAll().iterator();
 while (i.hasNext) {
   Artist artist = (Artist) i.next();
   domeSomethingWith(artist);
   Collection artistsRecords = artist.getRecords();
   doSomethingWith(records);
   ...

this would have to replaced with

// first pass to touch artists

 Iterator i = artistCollection.iterator();
 while (i.hasNext) {
     Artist artist = (Artist) i.next();
     doSomethingWith(artist);
 }

// second pass to touch records

 i = artistCollection.iterator();
 while (i.hasNext) {
     Artist artist = (Artist) i.next();
     doSomethingWith(artist.getRecords());
 }

to be exact, I don't think this is required if "finders load beans" is on
with WebLogic, but if I try to write portable code that does not help.

- Record.getArtist() could not be used at all. One would have to use
ArtistHome.findByRecordId() instead (not really classy).

Yes, I am using row level locking (Oracle).

- - -
Janne Mattila





=========================================================================== To unsubscribe, send email to [EMAIL PROTECTED] and include in the body of the message "signoff EJB-INTEREST". For general help, send email to [EMAIL PROTECTED] and include in the body of the message "help".

Reply via email to