这是我在这个网站上的第一篇文章,我很确定我会解决我的问题。我在 JPA 方面不太好,所以陷入了一个问题。无法分享完整的代码,但通过以下示例让您了解我想要实现的目标:
underOneMethod(){
Person personObj1 = entityManager.createNamedQuery("Select * from Person where smthing..");
personObj1.setFirstName("John");
personObj1 = entityManager.merge(personObj1);
entityManager.flush();
Person personObj2 = entityManager.createNamedQuery("Select * from Person where smthing..");
personObj2.setLastName("Cruz");
personObj2 = entityManager.merge(personObj1);
entityManager.flush();
} // This code throws me exception. I think it will work if I use entityManager.clear() method after first flush call but still it will be good, of someone can me some idea of what is happening in this case and how can it be resolved. Thanks in advance..!