Pojo: UserDetails
EntityManager: entityManager
1. Ceate Criteria
CriteriaBuilder builder = entityManager.getCriteriaBuilder();
CriteriaQuery<UserDetails> criteria = builder.createQuery(UserDetails.class);
Create Criteria
2. Compose SQL
1) table
Root<UserDetails> userDetailsTable = criteria.from(UserDetails.class);
From
2) Condition
Path<UserDetails> uId = userDetailsTable.get("userId");
Predicate condition = builder.equal(uId, userId);
criteria.where(condition);
Condition
3. result
return entityManager.createQuery(criteria).getSingleResult();
Result