سؤال

i have the following code in some thread runing, so far i can make it persist in the

        entityManager = DatabaseCommon.getEntityManager();

        entityManager.getTransaction().begin();
        entityManager.persist(smsReceived);
        entityManager.getTransaction().commit();

        sendedMo = sendMo(); //that method consumes a WS.

        if (sendedMo) {
            smsReceived.setSmsStatus("0");
        }

        entityManager.getTransaction().begin();
        entityManager.merge(smsReceived);
        entityManager.getTransaction().commit();

This is in a try catch blocks of course, so, the questions is: How to wait merge until a persist is made?

thx :)

هل كانت مفيدة؟

المحلول

After you persist(), you commit the transaction. After committing successfully you are guaranteed that the persist operation was correct, so you are free to merge() further, as you do. So your code seems OK to me.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top