08-根据id删除用户
作者:互联网
/*
删除客户案例
*/
@Test
public void testRemove(){
//1、通过工具类获取entityManager
EntityManager entityManager = JpaUtils.getEntityManager();
//2、开启事务
EntityTransaction tx = entityManager.getTransaction();
tx.begin();
//3、增删改查---删除客户
//(1)先根据id查询客户
Customer customer = entityManager.find(Customer.class, 1l);
//(2)调用remove方法进行删除
entityManager.remove(customer);
//4、提交事务
tx.commit();
//5、释放资源
entityManager.close();
}
标签:Customer,customer,entityManager,删除,tx,08,id 来源: https://www.cnblogs.com/morehair/p/15486886.html