Question

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 :)

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top