JPA thinks I'm deleting a detached object

前端 未结 7 2191
萌比男神i
萌比男神i 2020-12-14 00:30

I\'ve got a DAO that I used to load and save my domain objects using JPA. I finally managed to get the transaction stuff working, now I\'ve got another issue.

In my

相关标签:
7条回答
  • 2020-12-14 01:06

    Here is what I used (based on the previous answers)

    public void deleteTask(int taskId) {
        Task task = getTask(taskId); //this is a function that returns a task by id
        if (task == null) {
            return;
        }
        EntityManager em = emf.createEntityManager();
        EntityTransaction et = em.getTransaction();
        et.begin();
        em.remove(em.merge(task));
        et.commit();
        em.close();
    }
    
    0 讨论(0)
提交回复
热议问题