How does an entity get an ID before a transaction is committed in JPA/Play?

后端 未结 4 653
春和景丽
春和景丽 2020-12-19 05:47

See this question.

It turns out that even without committing the transaction manually, before the TX is committed, the person has an ID after calling the save() meth

4条回答
  •  一生所求
    2020-12-19 06:22

    Between begintransaction and commit, after call save or update method, you should use:

    EntityManagerHelper.getEntityManager().flush();
    

    If you dont call it, the Object will be lost and cant be save to DB.

    So after call it, you will take id of it in object.

提交回复
热议问题