简体   繁体   中英

Reading with Hibernate Criteria API

I'm using Hibernate Criteria API in my project. In this API, list() method is used to get a number of records from db. My question is : How to get only one record from db (without using list() method as there is no need)?

If you're certain that the query is going to return at most one record, use Criteria#uniqueResult() .

If the query can return more than one record, but you're fine with just getting the first result, you could combine uniqueResult() with Criteria#setMaxResults() .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM