DAO メソッドを使用しないでください。@Transactional
実際、DAO メソッドに直接アクセスしてはいけません。. @Service
サービスは操作を実行するために 0 個以上の DAO クラスを使用し、すべての操作が完了した後にのみトランザクションがコミットされます。
@Repository
public class CustomerDao() {
// dao methods here, they are not transactional but will be run within a sevice transaction
}
@Service
@Transactional
public class CustomerService() {
private final CustomerDao customerDao;
@Autowired
public CustomerService(CustomerDao customerDao) {
this.customerDao = customerDao;
}
//service methods here (they are all transactional because we have annotated the class)
}