You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Fight Ice <ri...@hotmail.com> on 2012/05/27 11:33:09 UTC

Hibernate Transaction

java code:

Transaction ts=session.beginTransaction();
Criteria criteria=session.createCriteria(Item.class);
criteria.add(Restrictions.idEq(product.getItem().getId()));
criteria.setLockMode(LockMode.PESSIMISTIC_WRITE);
Item item=(Item)criteria.list().get(0);
...
ts.commit();
...
Transaction tc=session.beginTransaction();
...
tc.commit();

Then I got the Exception:
Transaction not successfully started.


 		 	   		  

Re: Hibernate Transaction

Posted by Thiago H de Paula Figueiredo <th...@gmail.com>.
On Sun, 27 May 2012 06:33:09 -0300, Fight Ice <ri...@hotmail.com> wrote:

>
> java code:
>
> Transaction ts=session.beginTransaction();
> Criteria criteria=session.createCriteria(Item.class);
> criteria.add(Restrictions.idEq(product.getItem().getId()));
> criteria.setLockMode(LockMode.PESSIMISTIC_WRITE);
> Item item=(Item)criteria.list().get(0);
> ...
> ts.commit();
> ...
> Transaction tc=session.beginTransaction();
> ...
> tc.commit();
>
> Then I got the Exception:
> Transaction not successfully started.

This is a pure Hibernate question that shouldn't have been posted in the  
Tapestry users mailing list. Please stay on topic.

--
Thiago

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


Re: Hibernate Transaction

Posted by Kalle Korhonen <ka...@gmail.com>.
On Sun, May 27, 2012 at 7:18 PM, Fight Ice <ri...@hotmail.com> wrote:
> Thx, I use HibernateSessionSource.create(). Is this thread safe?

Are sessions thread safe? No.

Kalle

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


RE: Hibernate Transaction

Posted by Fight Ice <ri...@hotmail.com>.
Thx, I use HibernateSessionSource.create(). Is this thread safe?
 		 	   		  

Re: Hibernate Transaction

Posted by Kalle Korhonen <ka...@gmail.com>.
On Sun, May 27, 2012 at 2:33 AM, Fight Ice <ri...@hotmail.com> wrote:
> java code:
> Transaction ts=session.beginTransaction();
> Criteria criteria=session.createCriteria(Item.class);
> criteria.add(Restrictions.idEq(product.getItem().getId()));
> criteria.setLockMode(LockMode.PESSIMISTIC_WRITE);
> Item item=(Item)criteria.list().get(0);
> ts.commit();
> Transaction tc=session.beginTransaction();
> tc.commit();
> Then I got the Exception:
> Transaction not successfully started.

Any of these options:
1) If you use managed transactions (i.e. @CommitAfter) don't commit yourself
2) If you really want to use the same session, start a new transaction
after committing. But it's a very questionable practice
3) Use HibernateSessionSource.create() to manage transactions manually
in a separate session

Kalle

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