-3

我有使用hibernate orm与db一起工作的java应用程序?那么在数据库中检查记录存在(映射到休眠对象)的最快方法是什么

4

1 回答 1

5

使用entityManager.find.

文档中的示例:

long catId = 1234L;
em.find( Cat.class, new Long(catId) );

或者,计算记录:

Integer count = (Integer) session.createQuery("select count(*) from Cats c where c.id = :catId")
                          .setLong("catId", 1234L)
                          .uniqueResult();
boolean exists = count > 0;
于 2012-04-26T16:19:05.740 回答