@Test
public void testFind(){
//1、通过工具类获取entityManager
EntityManager entityManager = JpaUtils.getEntityManager();
//2、开启事务
EntityTransaction tx = entityManager.getTransaction();
tx.begin();
/*
3、增删改查---根据id查询客户
find:根据id查询客户
class:查询数据的结果需要包装的实体类类型的字节码
id:查询的主键的取值
*/
Customer customer = entityManager.find(Customer.class, 1l);
System.out.println(customer);
//4、提交事务
tx.commit();
//5、释放资源
entityManager.close();
}
@Test
public void testReference(){
//1、通过工具类获取entityManager
EntityManager entityManager = JpaUtils.getEntityManager();
//2、开启事务
EntityTransaction tx = entityManager.getTransaction();
tx.begin();
/*
3、增删改查---根据id查询客户
getReference:根据id查询客户
class:查询数据的结果需要包装的实体类类型的字节码
id:查询的主键的取值
*/
Customer customer = entityManager.getReference(Customer.class, 1l);
System.out.println(customer);
//4、提交事务
tx.commit();
//5、释放资源
entityManager.close();
}