0

I have a @Repository which extends from another class. Both classes can have @Transactional methods.

@Repository
public class InfoDAO extends BasicDAO<Info> {

    private void test1{
        test2();
    }
}

public class BasicDAO<T> {

    @Autowired
    EntityManager entityManager;

    @Transactional
    public void test2{
       entityManager.createNativeQuery(...).executeUpdate();
    }
}

If I call to a @Transactional method from a @Service, only works if the first method that I call is annotated with @Transactional.

For example if I call from the @Service to a method in InfoDAO and it calls to a @Transactional method in BasicDAO, it doesn't get the connection giving the error javax.persistence.TransactionRequiredException: Executing an update/delete query, but if I call from the @Service directly to the @Transactional method in BasicDAO, it gets the connection properly.

Why can't I go throught the InfoDAO class to BasicDAO class and call the @Transactional method to make an executeUpdate? By now, both classes (InfoDAO and BasicDAO) are in the same package.

sergiopf
  • 33
  • 8

0 Answers0