Java Persistence Query Language (JPA QL) Guide
1. Handling Non - Unique Results
When querying in Java Persistence, there’s a risk of getting a NonUniqueResultException . For example, if you search for all employees named ‘Dave’, there could be multiple matches. To avoid this exception, you can use the getResultList() method:
Query query = entityManager.createQuery(
"from Employee e where e.name='Dave'");
java.util.List<?> bills = query.getResultList();
The getResultList() method returns an empty list if no matching results are found, instead of throwing an exception.
2. Query Parameters
JPA QL allows you to specify parameters in
超级会员免费看
订阅专栏 解锁全文
71

被折叠的 条评论
为什么被折叠?



