1

I am new to hibernate and trying to learn . I have a table with name "Customer" and two columns "customer_Name" and "Cars"

   customer_name          Cars        
      A                    Ford
      A                    Hyundai
      A                    Audi
      B                    Merc
      B                    Volvo
      C                    AstonMartin
      C                    Nissan

Using hibernate ,how can I get the Cars each customer has based on his name . i.e. "customer_name" A has three "Cars" Ford,Hyundai and Audi. I want to use Criteria to do this . Can we do this without using hql queries?

1 Answer 1

1

Do it like this:

Criteria criteria = session.createCriteria(Customer.class);

if(customer_name!=null)
{
    criteria.add(Restrictions.eq("customer_name", customer_name));
}

List<Customer> customers = (Customers)criteria.list();

You can read more from Here.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.