Hibernate Books

All times are UTC - 5 hours [ DST ]



Post new topic Reply to topic  [ 1 post ] 
Author Message
 Post subject: Repeated calls to Transaction.begin()
PostPosted: Wed Jun 11, 2008 1:02 pm 
Newbie

Joined: Tue Jan 17, 2006 2:49 pm
Posts: 2
Is it legitimate to invoke Transaction.begin() after invoking Transaction.commit()?

Tapestry's Hibernate support is designed to automatically commit the transaction under user-control, then start a new transaction for any additional (usually read-only) behavior afterwards:

Code:
public class HibernateSessionManagerImpl implements HibernateSessionManager, ThreadCleanupListener
{
    private final Session session;

    private Transaction transaction;

    public HibernateSessionManagerImpl(HibernateSessionSource source)
    {
        session = source.create();

        transaction = session.beginTransaction();
    }



public void commit()
    {
        transaction.commit();
        transaction.begin();
    }


But I've gotten user feedback that this isn't working correctly because a second Transaction is being created.

I'm thinking I should change my code inside commit() to be

Code:
transaction.commit();
transaction = session.beginTransaction();



My question is, why is it possible (and not an IllegalStateException, for instance) to call begin() on a Transaction more than once?


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.