我有使用hibernate orm与db一起工作的java应用程序?那么什么是在db
中检查记录(映射到hibernate对象)的presense的最快方法答案 0 :(得分:5)
docs的示例:
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;