Skip to content

Instantly share code, notes, and snippets.

@MangoLiu
Created January 1, 2014 05:49
Show Gist options
  • Save MangoLiu/8205474 to your computer and use it in GitHub Desktop.
Save MangoLiu/8205474 to your computer and use it in GitHub Desktop.
Hibernate persistence operation (Hibernate 持久化操作的一般步骤)
public class NewsManager{
public static void main(String[] args) throws Exception{
//实例化Configuration
Configuration conf = new Configuration().configure();
//创建SessionFactory
SessionFactory sf = conf.buildSessionFactory();
//创建Session
Session session = sf.openSession();
//开始事务
Tracsaction tx = sess.beginTransaction();
//创建消息实体
News n = new News();
n.setTitle("Mango");
n.setContent("Liu");
//保存消息
session.save(n);
//提交事务
tx.commit();
//关闭session
session.close();
sf.close();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment