Reputation: 2708
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?
Upvotes: 1
Views: 117
Reputation: 7836
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.
Upvotes: 1