jdbc中的合并函数

jdbc中的合并函数,jdbc,Jdbc,对于所有三个syso,我的输出都是false,为什么?我不明白,即使我在begin()和commit之间编写syso,它也会将false作为输出。 提前感谢。合并可用于实体的克隆。 它首先将克隆的属性复制到工作单元副本中,然后管理克隆的实体,而不是您传递的原始实体。 您在示例中所期望的是em.persist(entity)操作。persist注册实体而不进行克隆。 尝试使用em.persist(entity),它将为您提供预期的结果。 合并操作是为RMI对象提供的,因此该行为也是如此。合并在实体

对于所有三个syso,我的输出都是false,为什么?我不明白,即使我在begin()和commit之间编写syso,它也会将false作为输出。
提前感谢。

合并可用于实体的克隆。
它首先将克隆的属性复制到工作单元副本中,然后管理克隆的实体,而不是您传递的原始实体。
您在示例中所期望的是
em.persist(entity)
操作。persist注册实体而不进行克隆。
尝试使用
em.persist(entity)
,它将为您提供预期的结果。

合并操作是为RMI对象提供的,因此该行为也是如此。合并在实体的克隆上起作用。
它首先将克隆的属性复制到工作单元副本中,然后管理克隆的实体,而不是您传递的原始实体。
您在示例中所期望的是
em.persist(entity)
操作。persist注册实体而不进行克隆。
尝试使用
em.persist(entity)
,它将为您提供预期的结果。
为RMI对象提供了合并操作,从而实现了该行为。

public static void merge() {
        EntityManagerFactory emf = Persistence.createEntityManagerFactory("LifeCycle");
        EntityManager em = null;
        try {
            em = emf.createEntityManager();
            System.out.println("--------------------------------------------------------");

            EmployeeEntity employee=new EmployeeEntity();
            employee.setEmpId(1002);
            //employee.setEmpId(1111);
            employee.setEmpLocation("Mysore");
            employee.setEmpName("Mahadeva");
            System.out.println("Before  merge   :  The EmployeeEntity instance is in MANAGED state  :" + em.contains(employee));
            em.merge(employee);
            System.out.println("After   merge   :  The EmployeeEntity instance is in MANAGED state  :" + em.contains(employee));

            em.getTransaction().begin();
            em.getTransaction().commit();
            System.out.println("After  Commit   :  The EmployeeEntity instance is in MANAGED state  :" + em.contains(employee));
            System.out.println("--------------------------------------------------------");
        } catch (Exception exception) {
            System.out.println(exception.getMessage());
        } finally {
            if(em!=null){
                em.close();
            }
            if (emf != null) {
                emf.close();

            }
        }
    }