if I have several DAOs to be injected into a Service that need to work together in a single transaction, how can I do this ?
@Component
public class CallerClass{
@Autowired
private TransactionClass1 class1;
@Autowired
private TransactionClass2 class2;
public void saveOperation(){
try{
class1.save();
class2.save();
}catch(Exception ex){
}
}
}
Like above simple codes. However, this code is lack
You would just inject all the DAOs in the same manner as you do normally i.e. setter or constructor using @Inject or @Autowired.
You then annotate your service method as Transactional and invoke the required operations on the multiple DAOs. The transaction will encompass all of the dao calls within it.