Вопрос

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