2

I refresh an entity with locktype PESSIMISTIC_WRITE.

Tab1 tab1 = em.find(Tab1.class, id, LockModeType.PESSIMISTIC_WRITE);
em.refresh(tab1, LockModeType.PESSIMISTIC_WRITE);

I have 3 tables:

public class Tab1{int id;String name;Tab2 tab2;}  
public class Tab2{int id;String name;Tab3 tab3;}  
public class Tab3{int id;String name;}   

Which data or tables will be locked (see example)?

1) Only the row with id in Tab1? 2) Entire table Tab1?
3) Entire table Tab1 and Tab2
4) Entire table Tab1,Tab2 and Tab3,because there are reference to tab2 and tab3?

ydaetskcoR
  • 53,225
  • 8
  • 158
  • 177
icit
  • 21
  • 4
  • You are locking the tab1 entity, so only that table would be locked unless you have cascade options set. You can verify by turning on logging and trying the statements to see what gets generated – Chris Nov 05 '14 at 15:20
  • Assuming that the default `PessimisticLockScope.Normal` is used, then 1) Only the row with id in Tab1 will be locked (exclusively); in case of `PessimisticLockScope.Extended` also relationships owned by tab1 entity would be locked – wypieprz Nov 05 '14 at 18:14

0 Answers0