I have a service which calls other services to perform DB operations. I have added a Transactional annotation on the method.
@Service
class myService {
@Autowired Service1....
@Transactional
public void saveData(String data) {
data = service1.changeData(data);
dao1.save1(data);
dao2.save2(data);
}
}
@Service
class Service1 {
.
.
.
public String changeData(String data) {
return dao3.getChangedData(data);
}
}
@Repository
class dao1 {
public void save1(String data) {
// INSERT DATA ...
}
}
@Repository
class dao2 {
public void save2(String data) {
// INSERT DATA ...
}
}
@Repository
@Transactional
class dao2 {
public String getChangedData(String data) {
// Get Data...
}
}
The problem is if something goes wrong in save2() method called from myService, the data inserted in save1 is not rolledback in the database. It still persists in the DB. Any idea why is this not working?
Thanks!