hibernate不知道怎么删除?
数据库表:CUSTOMER
字段:ID,NAME,PASSWOED
代码:
public static void main(String[] args) {
Configuration conf = new Configuration().configure();
SessionFactory sf = conf.buildSessionFactory();
Session se = sf.openSession();
List<Customer> list=null;
Customer cs=null;
Transaction tr = se.beginTransaction();
CustomerDAO dao = new CustomerDAO();
list = dao.findByProperty("name", "smile1");//mysql中已经存在的一个名为smile1的数据
list.listIterator().hasNext();
Iterator<Customer> it = list.iterator();
while(it.hasNext()){
cs=(Customer)it.next();
System.out.println(cs.getName());//查看是否取到了数据
dao.delete(cs);
}
tr.commit();
}
//CustomerDAO中的delete函数
public void delete(Customer persistentInstance) {
log.debug("deleting Customer instance");
try {
getSession().delete(persistentInstance);
log.debug("delete successful");
} catch (RuntimeException re) {
log.error("delete failed", re);
throw re;
}
}
显示已经查询到数据,可是到数据库看,smile1数据并没有删除,这是为什么?是否与持久化对象有关?我是新手,请指点,谢谢!