You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by tompeter <in...@tomkrause.com> on 2011/07/18 19:06:15 UTC

Tapestry5/Hibernate Persistence

Hi,

I hope you can help me answer a Tapestry5/Hibernate question.
In an onSuccessFromForm Method I want to update a database entity only if a
specific value of that entity is null.

This is how I do it:
Step 1: I read the entity with something like: myObject =
(Object)criteria.list().get(0);
Step 2: I check if myObject.specificValue == null ;
Step 3: If it is null I update the object and do
_session.persist(myUpdatedObject)
Step 4: I commit by :session.getTransaction().commit();

I inject the session with Tapestry annotation and think I am save, but still
not sure about:
Is this the correct implementation or is it possible that User2 updates the
entity after User1 has read the entity and before User1 has persisted the
entity? 

Thanks for your help and all best,
Tom

--
View this message in context: http://tapestry.1045711.n5.nabble.com/Tapestry5-Hibernate-Persistence-tp4600362p4600362.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: Tapestry5/Hibernate Persistence

Posted by tompeter <in...@tomkrause.com>.
Thanks Thiago, that's good to know!

--
View this message in context: http://tapestry.1045711.n5.nabble.com/Tapestry5-Hibernate-Persistence-tp4600362p4601140.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: Tapestry5/Hibernate Persistence

Posted by "Thiago H. de Paula Figueiredo" <th...@gmail.com>.
On Mon, 18 Jul 2011 17:28:19 -0300, tompeter <in...@tomkrause.com> wrote:

> It is not possible that a second user reads the entity before the
> HibernateSessionManager has committed the changes of User 1? I ask  
> because I use injected org.hibernate.Session for reading the values.

This isn't related to Tapestry at all, just to Hibernate itself, but the  
answer is yes. If you want to add an automatic check for it, check the  
otimistic lock section in the Hibernate documentation.

-- 
Thiago H. de Paula Figueiredo
Independent Java, Apache Tapestry 5 and Hibernate consultant, developer,  
and instructor
Owner, Ars Machina Tecnologia da Informação Ltda.
http://www.arsmachina.com.br

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


Re: Tapestry5/Hibernate Persistence

Posted by tompeter <in...@tomkrause.com>.
Great, thank you!
I am using the @CommitAfter Annotation now.
Just to make sure:
It is not possible that a second user reads the entity before the
HibernateSessionManager has committed the changes of User 1? I ask because I
use injected org.hibernate.Session for reading the values.

Thanks,
Tom

--
View this message in context: http://tapestry.1045711.n5.nabble.com/Tapestry5-Hibernate-Persistence-tp4600362p4601078.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: Tapestry5/Hibernate Persistence

Posted by Михаил Слободянюк <sl...@gmail.com>.
Hi!
Problem in you Step 4. Use
http://tapestry.apache.org/tapestry5/apidocs/org/apache/tapestry5/hibernate/HibernateSessionManager.html
 method *commit<http://tapestry.apache.org/tapestry5/apidocs/org/apache/tapestry5/hibernate/HibernateSessionManager.html#commit()>
*()or @CommitAfter annotation. See
http://tapestry.apache.org/hibernate-user-guide.html

2011/7/18 tompeter <in...@tomkrause.com>

> Hi,
>
> I hope you can help me answer a Tapestry5/Hibernate question.
> In an onSuccessFromForm Method I want to update a database entity only if a
> specific value of that entity is null.
>
> This is how I do it:
> Step 1: I read the entity with something like: myObject =
> (Object)criteria.list().get(0);
> Step 2: I check if myObject.specificValue == null ;
> Step 3: If it is null I update the object and do
> _session.persist(myUpdatedObject)
> Step 4: I commit by :session.getTransaction().commit();
>
> I inject the session with Tapestry annotation and think I am save, but
> still
> not sure about:
> Is this the correct implementation or is it possible that User2 updates the
> entity after User1 has read the entity and before User1 has persisted the
> entity?
>
> Thanks for your help and all best,
> Tom
>
> --
> View this message in context:
> http://tapestry.1045711.n5.nabble.com/Tapestry5-Hibernate-Persistence-tp4600362p4600362.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
>
>