use*_*444 -2 java hibernate query-optimization
我有使用hibernate orm与db一起工作的java应用程序?那么什么是在db中检查记录(映射到hibernate对象)的presense的最快方法
来自文档的示例:
long catId = 1234L;
em.find( Cat.class, new Long(catId) );
Run Code Online (Sandbox Code Playgroud)
或者,计算记录:
Integer count = (Integer) session.createQuery("select count(*) from Cats c where c.id = :catId")
.setLong("catId", 1234L)
.uniqueResult();
boolean exists = count > 0;
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4238 次 |
| 最近记录: |