天天看点

09-客户的更新操作

/*
    更新客户操作
        merge(Object)
     */
    @Test
    public void testUpdate(){
        //1、通过工具类获取entityManager
        EntityManager entityManager = JpaUtils.getEntityManager();
        //2、开启事务
        EntityTransaction tx = entityManager.getTransaction();
        tx.begin();
        //3、更新操作
        //(1)查询客户
        Customer customer = entityManager.find(Customer.class, 1l);
        //(2)更新客户
        customer.setCustIndustry("it教育");
        entityManager.merge(customer);
        //4、提交事务
        tx.commit();
        //5、释放资源
        entityManager.close();
    }
           

继续阅读