Re: Calling method after CommitAfter call

2016-02-24 Thread g kuczera
>
> But I think a JPA hook would be a better choice. The Interceptor hooks
> happen for *all* the transactions in your SessionFactory, and JPA hooks are
> more fine-grained.

I am not really into JPA thing, but if I understand well I have to add the
whole new configuration (in AppModule), as stated here:
https://tapestry.apache.org/integrating-with-jpa.html

All my classes are Daos and Dtos which uses the org,hibernate.Session (at
least the Daos).

2016-02-24 23:55 GMT+01:00 Thiago H de Paula Figueiredo 
:

> On Wed, 24 Feb 2016 19:33:13 -0300, g kuczera  wrote:
>
> I will try tomorrow the HibernateSessionManager.commit. But what do you
>> think, guys, about Hibernate Interceptor? It has something similar to
>> what Kalle mentioned, afterTransactionCompletion
>> and beforeTransactionCompletion. Have you ever used it with Tapestry?
>>
>
> The company I work uses it with Tapestry for some low-level stuff (mostly
> setting modified date properties automatically and similar stuff). But I
> think a JPA hook would be a better choice. The Interceptor hooks happen for
> *all* the transactions in your SessionFactory, and JPA hooks are more
> fine-grained.
>
>
> --
> Thiago H. de Paula Figueiredo
> Tapestry, Java and Hibernate consultant and developer
> http://machina.com.br
>
> -
> To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
> For additional commands, e-mail: users-h...@tapestry.apache.org
>
>


Re: Calling method after CommitAfter call

2016-02-24 Thread Thiago H de Paula Figueiredo

On Wed, 24 Feb 2016 19:33:13 -0300, g kuczera  wrote:


I will try tomorrow the HibernateSessionManager.commit. But what do you
think, guys, about Hibernate Interceptor? It has something similar to  
what Kalle mentioned, afterTransactionCompletion

and beforeTransactionCompletion. Have you ever used it with Tapestry?


The company I work uses it with Tapestry for some low-level stuff (mostly  
setting modified date properties automatically and similar stuff). But I  
think a JPA hook would be a better choice. The Interceptor hooks happen  
for *all* the transactions in your SessionFactory, and JPA hooks are more  
fine-grained.


--
Thiago H. de Paula Figueiredo
Tapestry, Java and Hibernate consultant and developer
http://machina.com.br

-
To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
For additional commands, e-mail: users-h...@tapestry.apache.org



Re: Calling method after CommitAfter call

2016-02-24 Thread g kuczera
>
> I'm sorry, I disagree. It's called Commit*After*, so I read that as the
> commit is done *after* the method call. It's not CommitWithin. :)


By using "module" I meant my piece of code:) Somebody - it was not me! -
have called the function before being sure, that the transaction is
committed. Or (s)he did not now, that CommitAfter commits after the hole
function being executed.

I will try tomorrow the HibernateSessionManager.commit. But what do you
think, guys, about Hibernate Interceptor? It has something similar to what
Kalle mentioned, afterTransactionCompletion
and beforeTransactionCompletion. Have you ever used it with Tapestry? I
think that I would have to have the queue with pending email-events and
serve/send them properly in afterTransactionCompletion. What do you think?

2016-02-24 22:35 GMT+01:00 Thiago H de Paula Figueiredo 
:

> On Wed, 24 Feb 2016 17:23:36 -0300, g kuczera  wrote:
>
> Hi guys,
>>
>
> Hi!
>
> It looks that the above module is badly designed. It does not matter that
>> there is the CommitAfter annotation, if I call the methods which assume
>> that everything is commited from within the commiting method.
>>
>> Am I right?
>>
>
> I'm sorry, I disagree. It's called Commit*After*, so I read that as the
> commit is done *after* the method call. It's not CommitWithin. :)
>
> Also, I completely agree with what Kalle said. If the annotation, which is
> a convenience for simple scenarios, doesn't fit your scenario, don't use
> it. Instead, you can use the HibernateSessionManager.commit() directly.
>
> --
> Thiago H. de Paula Figueiredo
> Tapestry, Java and Hibernate consultant and developer
> http://machina.com.br
>
> -
> To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
> For additional commands, e-mail: users-h...@tapestry.apache.org
>
>


Re: Calling method after CommitAfter call

2016-02-24 Thread Thiago H de Paula Figueiredo

On Wed, 24 Feb 2016 17:23:36 -0300, g kuczera  wrote:


Hi guys,


Hi!


It looks that the above module is badly designed. It does not matter that
there is the CommitAfter annotation, if I call the methods which assume
that everything is commited from within the commiting method.

Am I right?


I'm sorry, I disagree. It's called Commit*After*, so I read that as the  
commit is done *after* the method call. It's not CommitWithin. :)


Also, I completely agree with what Kalle said. If the annotation, which is  
a convenience for simple scenarios, doesn't fit your scenario, don't use  
it. Instead, you can use the HibernateSessionManager.commit() directly.


--
Thiago H. de Paula Figueiredo
Tapestry, Java and Hibernate consultant and developer
http://machina.com.br

-
To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
For additional commands, e-mail: users-h...@tapestry.apache.org



Re: Calling method after CommitAfter call

2016-02-24 Thread Kalle Korhonen
On Wed, Feb 24, 2016 at 12:27 PM, g kuczera  wrote:

> Sorry for not editing the post properly, I accidentally sent it by pressing
> the space few times (first time using the fullscreen editing on gmail).
>
> So, the question is if the hibernate Interceptor is the way to go? Do you
> have any other idea how to be 100% sure that my method from observer will
> be called after committing the changes?
>

The obvious choice is to manually commit the transaction, then notify the
observers. @CommitAfter is fine for simple cases but if the transaction is
rolled back, it doesn't allow you to react to it. If you still prefer
annotation, you could try out
https://github.com/satago/tapestry-jpa-transactions that support pre/after
commit hooks.

Kalle



> 2016-02-24 21:23 GMT+01:00 g kuczera :
>
> > Hi guys,
> > I embedded the ApplicationSubmitForm (component) in my Page. If it is
> > successfully validated, the onSuccessFromNewApplicationForm method is
> > called:
> >
> > private Set observers;
> >
> >   @CommitAfter
> >   public void onSuccessFromNewApplicationForm() {
> >
> > Application application = new Application();
> > application.setStatus(/* some value */);
> > application.setRegistrationDate(new Date());
> >
> > notifyObservers(application, true);
> >   }
> >
> > One of the observers - there is a field *observers*, which is a set -
> > sends an event to the mailing server. In 99% cases it works fine, but
> > sometimes the second application (on the different server), while
> checking
> > if an application indicated by the given id exists, does not find the
> > record. There is nothing like that in the database yet.
> >
> > It looks that the above module is badly designed. It does not matter that
> > there is the CommitAfter annotation, if I call the methods which assume
> > that everything is commited from within the commiting method.
> >
> > Am I right?
> >
> >
> >
>


Re: Calling method after CommitAfter call

2016-02-24 Thread g kuczera
Sorry for not editing the post properly, I accidentally sent it by pressing
the space few times (first time using the fullscreen editing on gmail).

So, the question is if the hibernate Interceptor is the way to go? Do you
have any other idea how to be 100% sure that my method from observer will
be called after committing the changes?

2016-02-24 21:23 GMT+01:00 g kuczera :

> Hi guys,
> I embedded the ApplicationSubmitForm (component) in my Page. If it is
> successfully validated, the onSuccessFromNewApplicationForm method is
> called:
>
> private Set observers;
>
>   @CommitAfter
>   public void onSuccessFromNewApplicationForm() {
>
> Application application = new Application();
> application.setStatus(/* some value */);
> application.setRegistrationDate(new Date());
>
> notifyObservers(application, true);
>   }
>
> One of the observers - there is a field *observers*, which is a set -
> sends an event to the mailing server. In 99% cases it works fine, but
> sometimes the second application (on the different server), while checking
> if an application indicated by the given id exists, does not find the
> record. There is nothing like that in the database yet.
>
> It looks that the above module is badly designed. It does not matter that
> there is the CommitAfter annotation, if I call the methods which assume
> that everything is commited from within the commiting method.
>
> Am I right?
>
>
>


Calling method after CommitAfter call

2016-02-24 Thread g kuczera
Hi guys,
I embedded the ApplicationSubmitForm (component) in my Page. If it is
successfully validated, the onSuccessFromNewApplicationForm method is
called:

private Set observers;

  @CommitAfter
  public void onSuccessFromNewApplicationForm() {

Application application = new Application();
application.setStatus(/* some value */);
application.setRegistrationDate(new Date());

notifyObservers(application, true);
  }

One of the observers - there is a field *observers*, which is a set - sends
an event to the mailing server. In 99% cases it works fine, but sometimes
the second application (on the different server), while checking if an
application indicated by the given id exists, does not find the record.
There is nothing like that in the database yet.

It looks that the above module is badly designed. It does not matter that
there is the CommitAfter annotation, if I call the methods which assume
that everything is commited from within the commiting method.

Am I right?