Click here to Skip to main content
15,917,862 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.


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.

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);
 .where(criteriaBuilder.equal(root.get("employeetype"), "Store Clerk"));
return employees = Employees)session.createQuery(criteriaQuery).getSingleResult();
Updated 14-Jun-21 8:26am
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