Click here to Skip to main content
15,885,985 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I want to write a boolean return type method using JPA criteria.

Like

Java
public boolean isEmployeeType(int id) {

// to do

return session.createQuery(criteriaQuery).getSingleResult();
}


I don't know how to accomplish this.

In following code snippet instead of return Employees I want to return boolean so when I'll call the method I don't need to check null but boolean.

like
Java
if(bLManager.isEmployeeType(12).false {
// to do
}


What I have tried:

 public Employees isEmployeeType(int id) {
        Employees employees;
        try (Session session = sf.openSession()) {
            CriteriaBuilder criteriaBuilder = sf.getCriteriaBuilder();
            CriteriaQuery criteriaQuery = criteriaBuilder.createQuery();

            Root root = criteriaQuery.from(Employees.class);

         criteriaQuery.select(criteriaBuilder.equal(root.get("id"),id))
 .where(criteriaBuilder.equal(root.get("employeetype"), "Store Clerk"));
return employees = Employees)session.createQuery(criteriaQuery).getSingleResult();
        }
    }
Posted
Updated 14-Jun-21 8:26am
v4
Comments
Mr.Corona 13-Jul-21 9:44am    
Can you Explain your question

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900