Created
January 1, 2014 05:49
-
-
Save MangoLiu/8205474 to your computer and use it in GitHub Desktop.
Hibernate persistence operation (Hibernate 持久化操作的一般步骤)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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