Hibernate 对象的几种状态

import org.hibernate.Session;
import org.hibernate.Transaction;

import po.Me;

public class TestHibernate {
public static void save() {
HibernateTools tool = new HibernateTools();

Session session = tool.getSession();
Transaction tra = session.beginTransaction();
tra.begin();
Me m = new Me();//(临时状态!)
m.setZhiye("teacher");
m.setName("tomjack");
session.save(m);
tra.commit();
Me mm=(Me)session.get(Me.class, new Integer(1));//(持久化状态)
//session.delete(mm);

tool.close();
mm.setName("adfasdfasdfasdf");
mm.setZhiye("dog");
session.update(mm);
System.out.println(m.getName());
}

public static void main(String[] args) {
save();
}
}

你可能感兴趣的:(Hibernate)