In spring, we have the @Transactional annotation, which can be specified in the controller, so everything happens inside the controller method, it is considered as one transaction. However, in the dropwizard, we can have a transaction at the DAO level by implementing the Transactional<DAOclass> . But if I use two DAOs in one resource method, it is considered as two different transactions.
Say I have two DAOs
Dao1.java
public abstract class Dao1 implements Transactional<Dao1>{ @sqlQuery(
Dao2.java
public abstract class Dao2 implements Transactional<Dao2>{ @sqlQuery(
ArticleResource.java
@POST @PATH("/articles") public void insertArticleAndItsChildren(Integer articleId){ try{ dao1.begin(); dao2.begin(); dao1.insertIntoArticles(); dao2.insertIntoArticlesChildren(); dao1.commit(); dao2.commit(); }catch(Exception e){ dao1.rollback(); dao2.rollback(); } }
In the above example, dao1 and dao2 have two different transactions. But I need ever under one transaction. So, is there a way to specify transaction boundaries at the resource level?
source share