From my experience, you really don't want to put CommitAfter on a generic 
method like that.

It really doesn't do what you expect in code like this:

void saveSomeData(List<Widget> widgets) {
  for (Widget w: widgets) {
    widgetDao.saveWidget(widget);
  }
}

In that case, assuming saveWidget is annotated with @CommitAfter, every 
iteration of the loop will commit separately, which is likely not what you want.

The @CommitAfter annotation is much better used in your page classes to commit 
transactions after a logical unit of work is complete.

Tony

> -----Original Message-----
> From: Eugen [mailto:eugens...@gmail.com]
> Sent: Wednesday, April 30, 2014 4:48 PM
> To: Tapestry users
> Subject: @CommitAfter for GenericDao
>
> Hi,
> I try to use the CommitAfter on a GenericDao, but the method does not
> commit the transaction. Does it exists a worcaround to do that?
>
> This is the code:
>
> public interface GenericDao<T> {
>     @CommitAfter
>     public void save(T entity);
> }
>
> public abstract class GenericDaoImpl<T> {
>     @Override
>     public void save(T entity) {
>         entityManager.persist(entity);
>     }
> }
>
> public interface UserDao extends GenericDao<User> { }
>
> public class UserDaoImpl extends GenericDaoImpl<User> implements
> UserDao { }
>
> and respective advisor in AppModule:
>
> @Match("*Dao")
> public static void adviseTransactions(JpaTransactionAdvisor advisor,
> MethodAdviceReceiver receiver) {
>         advisor.addTransactionCommitAdvice(receiver);
> }
>
> if I place the save() function into the UserDao all works fine.
>
> Thanks in advice
> Eugen
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
> For additional commands, e-mail: users-h...@tapestry.apache.org


Since 1982, Starpoint Solutions has been a trusted source of human capital and 
solutions. We are committed to our clients, employees, environment, community 
and social concerns.  We foster an inclusive culture based on trust, respect, 
honesty and solid performance. Learn more about Starpoint and our social 
responsibility at http://www.starpoint.com/social_responsibility

This email message from Starpoint Solutions LLC is for the sole use of  the 
intended recipient(s) and may contain confidential and privileged  information. 
 Any unauthorized review, use, disclosure or distribution is prohibited.  If 
you are not the intended recipient, please contact the sender by reply email 
and destroy all copies of the original message.  Opinions, conclusions and 
other information in this message that do not relate to the official business 
of Starpoint Solutions shall be understood as neither given nor endorsed by it.

Reply via email to