/*
使用jpql查询,统计客户的总数
sql:select count(cust_id) from cst_customer
spql:select count(custId) from Customer
*/
@Test
public void testCount(){
EntityManager entityManager = JpaUtils.getEntityManager();
EntityTransaction tx = entityManager.getTransaction();
tx.begin();
//查询全部
//根据jpql语句创建Query查询对象
String jpql = "select count(custId) from Customer";
Query query = entityManager.createQuery(jpql);
//对参数进行赋值
//发送查询,并封装结果
/*
getResultList: 直接将查询结果封装为List集合
getSingleResult:得到唯一的结果集
*/
Object singleResult = query.getSingleResult();
System.out.println(singleResult);
tx.commit();
entityManager.close();
}