-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Question about HelloWorld example
PostPosted: Mon Mar 26, 2007 8:45 pm 
Newbie

Joined: Wed Mar 21, 2007 1:12 pm
Posts: 19
Hi all,

In the helloworld example from hibernate tutorial, there is the following code to make two transactions (two units of work):

Code:
// First unit of work
        EntityManager em = emf.createEntityManager();
        EntityTransaction tx = em.getTransaction();
        tx.begin();
(...)
        tx.commit();
        em.close();

        // Second unit of work
        EntityManager newEm = emf.createEntityManager();
        EntityTransaction newTx = newEm.getTransaction();
        newTx.begin();

(...)

        newTx.commit();
        newEm.close();


Is this mandatory or one can use always the same EntityManager object and create only new Transactions? Which is the best way?

Code:
(it would be like this)
// First unit of work
        EntityManager em = emf.createEntityManager();
        EntityTransaction tx = em.getTransaction();
        tx.begin();
(...)
        tx.commit();
        //em.close();

        // Second unit of work
        //EntityManager newEm = emf.createEntityManager();
        EntityTransaction newTx = newEm.getTransaction();
        newTx.begin();
(...)
        newTx.commit();

(more transactions....)

        em.close();


Thanks in advance,
Rui


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 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.