package com.li.www.test;
public class ManyToMany {
public static void main(String[] args) {
Configuration conf=null;
SessionFactory sessionFactory=null;
Session session=null;
Transaction tr=null;
try{
conf=new Configuration().configure();//解析配置文件
sessionFactory=conf.buildSessionFactory();//建立sessionfactory
session=sessionFactory.openSession();//打开session
tr=session.beginTransaction();//开启事务
//查询
User user = new User();
User = session.load/get(User.class,id);
System.out.println("**"+cr.getCid());
//增加
User user = new User();
user.setUserid(***);
user.setUserName(“***”);
Session.save(user);
//删除或修改都必须先查询在执行
session.delete/session.update
tr.commit();//提交事务
}catch(HibernateException e){
tr.rollback();//事务回滚
e.printStackTrace();
}finally{ //关闭资源
session.close();
sessionFactory.close();
}
}
}