You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Pillar <so...@hotmail.com> on 2012/11/28 20:59:19 UTC
@CommitAfter not committing my transaction
Unless I'm understanding it wrong, the @CommitAfter on my method isn't
committing the transaction.
@CommitAfter
public void call() {
Session s = HibernateUtils.getSessionFactory().openSession();
s.beginTransaction();
User u = new User();
u.setUsername("Pillar");
u.setEmail("yahoo123@yahoo.ca");
u.setPassword("poof");
s.save(u);
}
Once execution exits this method and my page is rendered, I check my
database and there is no entry for the above user.
I'm on Tapestry 5.3 and have all the dependencies for tapestry-hibernate.
What am I doing wrong?
--
View this message in context: http://tapestry.1045711.n5.nabble.com/CommitAfter-not-committing-my-transaction-tp5718364.html
Sent from the Tapestry - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org
Re: @CommitAfter not committing my transaction
Posted by Lenny Primak <lp...@hope.nyc.ny.us>.
I am not sure, never used Tapestry transaction support,
but if you want full transaction support, use JEE
On Nov 29, 2012, at 5:06 PM, Pillar <so...@hotmail.com> wrote:
> More questions:
>
> I have an onSuccess() method in my Page class that calls a DAO delete method
> annotated with @CommitAfter. When the onSuccess() gets called (I'm using a
> form with a submit) the delete doesn't get commit at the end of the request
> (although I see hibernate log it). If I annotate the onSuccess() method with
> @CommitAfter, then the delete is commit and the entity is no longer in my
> db. Is this what you meant by doesn't support nesting? What is up?
>
>
>
> --
> View this message in context: http://tapestry.1045711.n5.nabble.com/CommitAfter-not-committing-my-transaction-tp5718364p5718407.html
> Sent from the Tapestry - User mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org
Re: @CommitAfter not committing my transaction
Posted by Pillar <so...@hotmail.com>.
Answer my question too. I read that little bit you linked and I understand
the HibernateTransactionAdvisor does it for you.
--
View this message in context: http://tapestry.1045711.n5.nabble.com/CommitAfter-not-committing-my-transaction-tp5718364p5718408.html
Sent from the Tapestry - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org
Re: @CommitAfter not committing my transaction
Posted by Pillar <so...@hotmail.com>.
More questions:
I have an onSuccess() method in my Page class that calls a DAO delete method
annotated with @CommitAfter. When the onSuccess() gets called (I'm using a
form with a submit) the delete doesn't get commit at the end of the request
(although I see hibernate log it). If I annotate the onSuccess() method with
@CommitAfter, then the delete is commit and the entity is no longer in my
db. Is this what you meant by doesn't support nesting? What is up?
--
View this message in context: http://tapestry.1045711.n5.nabble.com/CommitAfter-not-committing-my-transaction-tp5718364p5718407.html
Sent from the Tapestry - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org
Re: @CommitAfter not committing my transaction
Posted by Pillar <so...@hotmail.com>.
While we are on the subject. @CommitAfter commits the transaction after the
called method. What if I call multiple methods annotated with @CommitAfter?
The commits happen after each of them. If I reach a method where an
Exception is raised and I need to rollback, will it rollback every
transaction performed on the session?
I'm assuming no. How do you manage that?
--
View this message in context: http://tapestry.1045711.n5.nabble.com/CommitAfter-not-committing-my-transaction-tp5718364p5718406.html
Sent from the Tapestry - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org
Re: @CommitAfter not committing my transaction
Posted by Howard Lewis Ship <hl...@gmail.com>.
The idea with @CommitAfter is that Tapestry is responsible for handling the
transaction, using the session-in-view pattern. The session is created
lazily, when first needed. The transaction for the session is committed at
the end of a method with @CommitAfter. The session is available to be
injected using the plain @Inject annotation.
Some notes:
@CommitAfter works with no additional work on methods of pages and
components, but takes some extra configuration when used with services (see
the bottom of http://tapestry.apache.org/hibernate-user-guide.html).
@CommitAfter does not nest, though that may change in 5.4.
Tapestry's built-in Hibernate support only supports a single database; if
you are doing something more complicated (and I really must say: do you
really want to? Can you break things apart using a web service or JMS
instead, but I digress) ... well, you are on your own.
Finally, that Session object injected is a global proxy that delegates to
the a per-thread instance, so don't worry about concurrency. In the world
of servlets, per-thread and per-request are effectively synonymous.
On Thu, Nov 29, 2012 at 10:36 AM, Thiago H de Paula Figueiredo <
thiagohp@gmail.com> wrote:
> On Wed, 28 Nov 2012 22:28:58 -0200, Pillar <so...@hotmail.com> wrote:
>
> Ok, so I didn't know that, I thought SessionFactory was a singleton.
>>
>
> It never was. If you're connecting to two different databases, you'll need
> a SessionFactory for each.
>
>
> --
> Thiago H. de Paula Figueiredo
>
> ------------------------------**------------------------------**---------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.**apache.org<us...@tapestry.apache.org>
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>
--
Howard M. Lewis Ship
Creator of Apache Tapestry
The source for Tapestry training, mentoring and support. Contact me to
learn how I can get you up and productive in Tapestry fast!
(971) 678-5210
http://howardlewisship.com
Re: @CommitAfter not committing my transaction
Posted by Thiago H de Paula Figueiredo <th...@gmail.com>.
On Wed, 28 Nov 2012 22:28:58 -0200, Pillar <so...@hotmail.com> wrote:
> Ok, so I didn't know that, I thought SessionFactory was a singleton.
It never was. If you're connecting to two different databases, you'll need
a SessionFactory for each.
--
Thiago H. de Paula Figueiredo
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org
Re: @CommitAfter not committing my transaction
Posted by Pillar <so...@hotmail.com>.
Ok, so I didn't know that, I thought SessionFactory was a singleton. I will
use Tapestry-Hibernate the way it's meant to just like in the link you
posted. Thanks!
--
View this message in context: http://tapestry.1045711.n5.nabble.com/CommitAfter-not-committing-my-transaction-tp5718364p5718380.html
Sent from the Tapestry - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org
Re: @CommitAfter not committing my transaction
Posted by Josh Canfield <jo...@gmail.com>.
Tapestry-Hibernate creates it's own instance of the SessionFactory
http://tapestry.apache.org/current/apidocs/index.html?org/apache/tapestry5/internal/hibernate/HibernateSessionSourceImpl.html
You can have multiple SessionFactory instances (if you have multiple
databases for instance) so calling the static "getCurrentSession()" doesn't
make sense in this context.
I think you're trying to mix two paradigms. If you're working on a new
project consider doing things the Tapestry way. No HibernateUtils, @Inject
the session, or the HibernateSessionManager depending on what you need.
http://tapestry.apache.org/using-tapestry-with-hibernate.html
If you're trying to integrate into another system then give us some more
background on what you can and can't change and maybe someone will provide
some pointers.
Josh
On Wed, Nov 28, 2012 at 4:04 PM, Pillar <so...@hotmail.com> wrote:
> As far as I know a Hibernate Session has only one Transaction at a time,
> hence the session.beginTransaction, session.getTransaction(). Also, the
> SessionFactory has the getCurrentSession() which returns a per thread
> session. So unless, I'm completely wrong in how I think tapestry-hibernate
> is implemented, it shouldn't have to much hard time finding the session
> from
> the SessionFactory, either starting the transaction itself or not, and then
> getting the transaction from the session and committing it.
>
>
>
> --
> View this message in context:
> http://tapestry.1045711.n5.nabble.com/CommitAfter-not-committing-my-transaction-tp5718364p5718374.html
> Sent from the Tapestry - User mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>
Re: @CommitAfter not committing my transaction
Posted by Pillar <so...@hotmail.com>.
As far as I know a Hibernate Session has only one Transaction at a time,
hence the session.beginTransaction, session.getTransaction(). Also, the
SessionFactory has the getCurrentSession() which returns a per thread
session. So unless, I'm completely wrong in how I think tapestry-hibernate
is implemented, it shouldn't have to much hard time finding the session from
the SessionFactory, either starting the transaction itself or not, and then
getting the transaction from the session and committing it.
--
View this message in context: http://tapestry.1045711.n5.nabble.com/CommitAfter-not-committing-my-transaction-tp5718364p5718374.html
Sent from the Tapestry - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org
Re: @CommitAfter not committing my transaction
Posted by Josh Canfield <jo...@gmail.com>.
I'm not sure why you'd expect Tapestry to find a session that it didn't
create and commit a transaction that it doesn't know about?
On Wed, Nov 28, 2012 at 1:07 PM, Pillar <so...@hotmail.com> wrote:
> It is in a Controller. If it was in DAO Layer, do I still use the @Inject
> for
> a session or get it from HibernateUtils style class?
>
> Now regardless of if I get the Transaction from the Session I'm given from
> the SessionFactory, shouldn't Tapestry be finding the same Transaction and
> committing it?
>
>
>
> --
> View this message in context:
> http://tapestry.1045711.n5.nabble.com/CommitAfter-not-committing-my-transaction-tp5718364p5718367.html
> Sent from the Tapestry - User mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>
RE: @CommitAfter not committing my transaction
Posted by Pillar <so...@hotmail.com>.
It is in a Controller. If it was in DAO Layer, do I still use the @Inject for
a session or get it from HibernateUtils style class?
Now regardless of if I get the Transaction from the Session I'm given from
the SessionFactory, shouldn't Tapestry be finding the same Transaction and
committing it?
--
View this message in context: http://tapestry.1045711.n5.nabble.com/CommitAfter-not-committing-my-transaction-tp5718364p5718367.html
Sent from the Tapestry - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org
RE: @CommitAfter not committing my transaction
Posted by Tony Nelson <tn...@starpoint.com>.
You should also Inject the session.
@Inject
private Session session;
Is this method in a controller, or do you have a DAO layer?
-----Original Message-----
From: Pillar [mailto:sotodel_89@hotmail.com]
Sent: Wednesday, November 28, 2012 2:59 PM
To: users@tapestry.apache.org
Subject: @CommitAfter not committing my transaction
Unless I'm understanding it wrong, the @CommitAfter on my method isn't committing the transaction.
@CommitAfter
public void call() {
Session s = HibernateUtils.getSessionFactory().openSession();
s.beginTransaction();
User u = new User();
u.setUsername("Pillar");
u.setEmail("yahoo123@yahoo.ca");
u.setPassword("poof");
s.save(u);
}
Once execution exits this method and my page is rendered, I check my database and there is no entry for the above user.
I'm on Tapestry 5.3 and have all the dependencies for tapestry-hibernate.
What am I doing wrong?
--
View this message in context: http://tapestry.1045711.n5.nabble.com/CommitAfter-not-committing-my-transaction-tp5718364.html
Sent from the Tapestry - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@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.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org
Re: @CommitAfter not committing my transaction
Posted by Thiago H de Paula Figueiredo <th...@gmail.com>.
On Wed, 28 Nov 2012 22:16:35 -0200, Pillar <so...@hotmail.com> wrote:
> I'm not in a position to test it right now, so I won't say if it worked.
> Where does Tapestry get that session for you?
If you're using tapestry-hibernate and @Inject'ing it, @CommitAfter will
work. Otherwise, no.
--
Thiago H. de Paula Figueiredo
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org
Re: @CommitAfter not committing my transaction
Posted by Pillar <so...@hotmail.com>.
I'm not in a position to test it right now, so I won't say if it worked.
Where does Tapestry get that session for you? But you are right, that is
smarter/better than popping out your own every time.
--
View this message in context: http://tapestry.1045711.n5.nabble.com/CommitAfter-not-committing-my-transaction-tp5718364p5718377.html
Sent from the Tapestry - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org
Re: @CommitAfter not committing my transaction
Posted by Jay Ginete <ki...@gmail.com>.
I believe you are suppose to "inject" the Hibernate session.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org
Re: @CommitAfter not committing my transaction
Posted by Norman Franke <no...@myasd.com>.
I don't think you should start your own transaction. Remove the beginTransaction().
Norman Franke
Answering Service for Directors, Inc.
www.myasd.com
On Nov 28, 2012, at 2:59 PM, Pillar wrote:
> Unless I'm understanding it wrong, the @CommitAfter on my method isn't
> committing the transaction.
>
> @CommitAfter
> public void call() {
> Session s = HibernateUtils.getSessionFactory().openSession();
> s.beginTransaction();
> User u = new User();
> u.setUsername("Pillar");
> u.setEmail("yahoo123@yahoo.ca");
> u.setPassword("poof");
> s.save(u);
> }
>
> Once execution exits this method and my page is rendered, I check my
> database and there is no entry for the above user.
>
> I'm on Tapestry 5.3 and have all the dependencies for tapestry-hibernate.
>
> What am I doing wrong?
>
>
>
> --
> View this message in context: http://tapestry.1045711.n5.nabble.com/CommitAfter-not-committing-my-transaction-tp5718364.html
> Sent from the Tapestry - User mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>