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?

4

1 回答 1

1

像这样做:

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

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

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

您可以从这里阅读更多信息。

于 2013-08-14T10:41:29.517 回答