0

I have 3 EJB stateless beans. A - on business layer. B, C - of persistence layer.

Bean A calls B and C to update some data in database (DB2).

But unfortunatly, on calling bean C, database locks. Is it possible that B and C executes in defferent transactions? Otherwise I can't understand why DB2 locks...

obogoliy
  • 31
  • 4

2 Answers2

0

If you are using hibernate as your persistence provider, then it provides a transaction annotation called @TransactionAttribute(REQUIRES_NEW) on the business method. This annotation runs the method in a separate transaction. So I think there should be an alternative for this in JPA. But not sure.

DaveShaw
  • 52,123
  • 16
  • 112
  • 141
Lokesh Kumar P
  • 369
  • 5
  • 20
  • So, If I not put this annotation on business method, then no transaction will be started. Separate transactions will be for B and C? – obogoliy Jun 14 '12 at 12:54
  • If you dont put this annotation then the method will run in the parent transaction, that is the transaction will complete if the parent method which invoked this method completes. And I am assuming that you are invoking methods in B & C from A so till A completes B and C will run in same transaction – Lokesh Kumar P Jun 15 '12 at 04:53
  • Also can you please post your code, if it is not confidential ?? – Lokesh Kumar P Jun 15 '12 at 05:14
0

I have JBoss AS 7. I have two entities Employer and EMployee. Employee has link to employer.

I have

@Stateless
EployerService {
 ....
 public void lockEmployer (long id) {
    Employer employer = employerDAO.findById(id);
    employer.setLocked(true);
    employerDAO.updateEmployer(employer);
    employeeDAO.updateEmployeesByEmployerId(id);
 }  
}

in EmployeeDAO

updateEmployeesByEmployerId (long empId) {
   em.createQuery("update Employee set locked = true where emplopyerId=:id").setParameter("id", empId).executeUpdate();

}

in EmployerDAO

udpateEmplopyer(Employer employer) {
  em.merge(employer);
}

When I put all logic from both dao in one DAO - no locks!

obogoliy
  • 31
  • 4