HQL条件简单查询

public List queryData() {
List list = null;
Session session = HibernateSessionFactory.getSession();
Transaction tx = session.beginTransaction();
String sql = "from BasicUser as g where g.id>:id";
Query query = session.createQuery(sql);
query.setInteger("id", 86);
list = query.list();
tx.commit();
session.close();
return list;
}

public static void main(String[] args) {
List list = new HibernateTools().queryData();
for (int i = 0; i < list.size(); i++) {
BasicUser bu = (BasicUser) list.get(i);
System.out.println(bu.getId() + "," + bu.getName());
}
}

你可能感兴趣的:(sql)