Hibernate入门(四)检索

SQL检索

SQLQuery query = session.createSQLQuery("select * from student");

    query.addEntity(Student.class);

    Iterator iterator = query.list().iterator();

 

query = session.createSQLQuery("select {s.*} from student s");

    query.addEntity("s", Student.class);

    iterator = query.list().iterator();

 

SQLQuery query = session.createSQLQuery("select s.id as {stu.id}, s.name as {stu.name} from student s");

       query.addEntity("stu", Student.class);

 

SQLQuery query = session.createSQLQuery("select {stu.*},{tea.*} from student stu, teacher tea");

       query.addEntity("stu", Student.class);

       query.addEntity("tea", Teacher.class);

 

 

QBC

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

       Criterion criterion = Expression.eq("name", "2");      

       criteria.add(criterion);   

       criteria.list();

 

    Expression.le()年龄上限 ge()下限  and(criterion1,criterion2)

in,like,between,or,addOrder,

你可能感兴趣的:(sql,Hibernate)