Hi,
The tapestry-jpa-transactions module doesn't use any JPA interceptors, its
before/after commit hooks are implemented in the same advice that opens and
commits transactions for @CommitAfter. In theory you could do the same for
Hibernate too.
But in your case you could extract business logic that deals with
applicationDao to another service's method, put @CommitAfter annotation on
that method, and you're done, i.e.:
public void onFormSubmit(Object observable, Object o)
{
Application application = (Application) o;
applicationService.updateUser(application, user);
// transaction will be committed here
publisher.sendApplicationSubmittedMessage(
user.getId(), application.getId());
}
public interface ApplicationService
{
@CommitAfter
void updateUser(Application application, User user);
}
On Fri, Feb 26, 2016 at 1:54 PM, g kuczera <[email protected]> wrote:
> Thanks for the comprehensive answer. Right now I am testing the
> HibernateSessionManager usage.
> I added it as the field in my page:
> @Inject
> private HibernateSessionManager hibernateSessionManager;
>
> and then I commit it in the onFormSubmit method:
>
> public void onFormSubmit(Object observable, Object o) {
> Application application = (Application) o;
> application.setUser(user);
> applicationDao.save(application);
> hibernateSessionManager.commit();
>
> publisher.sendApplicationSubmittedMessage(user.getId(),
> application.getId());
> }
>
> But I feel quite ashamed of this solution. It's like forcing the inner
> mechanism of Tapestry's Hibernate Wrapper (or even the Hibernate by itself,
> it's flow) to commit the thing before it is appropriate.
>
> However switching from Hibernate to JPA is not an option for me and
> Interceptors, if I understand them well, seems like an overhead.
>
> 2016-02-25 15:52 GMT+01:00 Thiago H de Paula Figueiredo <
> [email protected]>
> :
>
> > On Thu, 25 Feb 2016 11:30:44 -0300, g kuczera <[email protected]>
> wrote:
> >
> > In the end I gave up implementing the JPA, because I do not want to mix
> >> these two different approaches (Hibernate sessions and JPA).
> >>
> >
> > The suggestion would be using JPA instead of Hibernate, not mixing them.
> >
> > So I have one questions: where do I find the HibernateSessionManager
> >> implementation?
> >>
> >
> >
> >
> https://github.com/apache/tapestry5/blob/master/tapestry-hibernate-core/src/main/java/org/apache/tapestry5/internal/hibernate/HibernateSessionManagerImpl.java
> >
> > It looks that I can't use regular
> >> session.getTransaction().commit() becase it gives me *Transaction not
> >> successfully started *error.
> >>
> >
> > In this case, you should start the transaction manually, just as you
> > commit it manually.
> >
> > I have been reading about these (hibernate and tapestry) machanisms and
> it
> >> looks that every thread has it's own session, which is being managed by
> >> HibernateSessionManager. I am not pretty sure how to obtain that
> manager,
> >> to safely commit the transaction.
> >>
> >
> > It's a Tapestry-IoC service, so you can @Inject it in your pages or have
> > it automatically injected into your services' constructors.
> >
> >
> > --
> > Thiago H. de Paula Figueiredo
> > Tapestry, Java and Hibernate consultant and developer
> > http://machina.com.br
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: [email protected]
> > For additional commands, e-mail: [email protected]
> >
> >
>
--
Dmitry Gusev
AnjLab Team
http://anjlab.com