Hi I need the following clarification on spring transaction. Seen is like:
Service1.java
@Service
@Repository
public class Service1 {
@Autowired
EmployeeRepo employeeRepo;
@Autowired
Repo repo;
@Transactional
public void m() {
employeeRepo.save(new Employee(5, "N3", 33, 3000));
repo.m1(); //M1
//m1(); //M2
System.out.println(1/0); //M3
}
@Transactional(propagation=Propagation.REQUIRES_NEW)
public void m1() {
Employee e=employeeRepo.findOne(1);
//System.out.println(1/0); //M4
e.setAge(212);
}
}
Repo.java
@Repository
class Repo{
@Autowired
EmployeeRepo employeeRepo;
@Transactional(propagation=Propagation.REQUIRES_NEW)
public void m1() {
Employee e=employeeRepo.findOne(1);
//System.out.println(1/0); //M5
e.setAge(212);
}
}
cases:
When executing as it is then no insertion but only update is done with exception 2.(reset)When commenting M1 and un commenting M2 then no insertion no update is done with exception (method in same class)
3.(reset)When uncommenting M5 and commenting M3 then no insertion no update is done with exception
4.(reset)When uncommenting M2,M4 and commenting M1,M3 then no insertion no update is done with exception
NOTE: same m1() method is in same caller calss and in diffrent class also. So why is this different behaviour of same operation in diffrent class? What is the concept then?