@Test public void testWhere4() { String hql = " from Customer c where c.age>20 "; Query query = session.createQuery(hql); Customer c = (Customer) query.uniqueResult(); System.out.println(c.getName()); }
@Test public void testWhere1() { String hql = " from Customer c where c.sex<>'ÄÐ'"; Query query = session.createQuery(hql); List<Customer> customers = query.list(); for (Customer c : customers) { System.out.println("name:" + c.getName()); System.out.println("sex:" + c.getSex()); } }
@Test public void testWhere2() { String hql = " from Customer c where c.age not between 20 and 40 "; Query query = session.createQuery(hql); List<Customer> customers = query.list(); for (Customer c : customers) { System.out.println("name:" + c.getName()); System.out.println("age:" + c.getAge()); } }
@Test public void testWhere3() { String hql = " from Customer c where c.address like '%±±¾©%'"; Query query = session.createQuery(hql); List<Customer> customers = query.list(); for (Customer c : customers) { System.out.println("name:" + c.getName()); System.out.println("address :" + c.getAddress()); } }
@Test public void testOrderby() { String hql = " from Customer order by age desc "; Query query = session.createQuery(hql); List<Customer> customers = query.list(); for (Customer c : customers) { System.out.println("name:" + c.getName()); System.out.println("age:" + c.getAge()); } }
@Test public void testFromClause() { String hql = " from Customer "; Query query = session.createQuery(hql); List<Customer> customers = query.list(); for (Customer customer : customers) { System.out.println("name:" + customer.getName()); } }