문제

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