Session session = HibernateSessionFactory.getSession();获得连接
Transaction transaction = session.beginTransaction();//事务开启
session.createSQLQuery(sql);//执行SQL语句但返回的多行不是帮你封装好的对象而是一个个对象数组
用HQL语句就是把以前写的表单写成对象的属性
from UserPO where name = :name and password = :password
query.setString("name", user.getName());
query.setString("password", user.getPassword());
query.setParameter("name", user.getName());
query.setParameter("password", user.getPassword());//可以通过这个方式设置值
但是··,Date不能通过这个方法赋值
查询
用get 和lond的区别
lond要报异常 get 不会返回一个空
lond支持延迟加载 get:不支持延迟加载
用Lis遍历知会生成一条SQL语句
Iterator:会生成N+1条语句//它首先查询出所有记录的ID再根据ID查询。