关于Hibernate的一点东西
2010-07-21 21:34
579 查看
package com.itttop.hibernate;
import java.util.Date;
import java.util.Properties;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;
import com.itttop.vo.Student;
public class Test {
/**
* @param args
*/
public static void main(String[] args) {
//1.得到配置环境
Configuration cfg = new Configuration();
//读取xml文件需要单独调用Configure()方法
cfg.configure();
// cfg.setProperty("hibernate.dialect", "org.hibernate.dialect.Oracle10gDialect");
// cfg.setProperty("hibernate.connection.driver_class", "oracle.jdbc.driver.OracleDriver");
// cfg.setProperty("hibernate.connection.username", "scott");
// cfg.setProperty("hibernate.connection.password", "tiger");
// cfg.setProperty("hibernate.connection.url", "jdbc:oracle:thin:@localhost:1521:orcl");
// cfg.setProperty("hibernate.hbm2ddl.auto","update");
// cfg.addResource("com/itttop/vo/Student.hbm.xml");
//2.通过配置环境得到SessionFactory
SessionFactory factory = cfg.buildSessionFactory();
//3.通过SessionFactory得到Session
// Session session = factory.openSession();
Session session = factory.getCurrentSession();
Student stu = new Student(1L,"雷朝成","男",new Date());
//4.通过Session得到Transaction
Transaction trans = session.beginTransaction();
session.save(stu);
trans.commit();
//5.关闭资料
// session.close();
// factory.close();
}
}
import java.util.Date;
import java.util.Properties;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;
import com.itttop.vo.Student;
public class Test {
/**
* @param args
*/
public static void main(String[] args) {
//1.得到配置环境
Configuration cfg = new Configuration();
//读取xml文件需要单独调用Configure()方法
cfg.configure();
// cfg.setProperty("hibernate.dialect", "org.hibernate.dialect.Oracle10gDialect");
// cfg.setProperty("hibernate.connection.driver_class", "oracle.jdbc.driver.OracleDriver");
// cfg.setProperty("hibernate.connection.username", "scott");
// cfg.setProperty("hibernate.connection.password", "tiger");
// cfg.setProperty("hibernate.connection.url", "jdbc:oracle:thin:@localhost:1521:orcl");
// cfg.setProperty("hibernate.hbm2ddl.auto","update");
// cfg.addResource("com/itttop/vo/Student.hbm.xml");
//2.通过配置环境得到SessionFactory
SessionFactory factory = cfg.buildSessionFactory();
//3.通过SessionFactory得到Session
// Session session = factory.openSession();
Session session = factory.getCurrentSession();
Student stu = new Student(1L,"雷朝成","男",new Date());
//4.通过Session得到Transaction
Transaction trans = session.beginTransaction();
session.save(stu);
trans.commit();
//5.关闭资料
// session.close();
// factory.close();
}
}
相关文章推荐
- 关于操作系统的一点东西
- 今天学到的关于UI的一点东西
- 关于Hibernate一点体会
- qt关于模态非模态的一点东西
- 关于java对象初始化的一点有意思的东西
- 关于hibernate对视图的操作的一点心得
- 关于MySQL 的一点东西
- hibernate4.2关于sessionFactory的一点变化
- 关于iPhone App的 Memory warning的一点东西
- 今天翻译了英文版书关于Mirus组件的一点东西,感觉还是有收获的~
- 关于Struts, Spring, Hibernate的一点文字
- 关于BIOS的一点东西
- 关于hibernate 是否选择关联查询(full,out,inner)时判断的一点体会
- 关于函数指针的一点东西
- 关于iPhone App的 Memory warning的一点东西
- 关于strace的一点东西
- 关于flash嵌入的一点东西 ----遗漏的知识点
- 关于一点HTML的东西(2)
- hibernate事务的一点东西
- 关于dialog的一点东西