1st day of hibernate: Hibenate 初窥
hibernate的开发流程:
1:导入所需要的Jar包(对于初学者,可以导入lib下的所有Jar包和hibernate3.jar);
(一般还需要导入对应的数据库驱动)
2:编写hibernate.cfg.xml配置文件或hibernate.properties文件(该文件主要配置连接数据库的一些信息,
eg: url、driver、username、password and so on.)
3:编写domain对象, at the same time,编写对应的映射文件(eg:domain class is 'User' ,the mapping file
shouldbe 'User.hbm.xml' )
4. 利用hibernate 提供的API进行相应的数据库操作。(eg:Configuration , SessionFactory , Session ,
Transaction, Query , Criteria, Restriction etc)
Hibernate development Process Example Code:
public class Base {
public static void main(String[] args) {
Configuration cfg = new Configuration();
cfg.configure();
SessionFactory sf = cfg.buildSessionFactory();
Session s = sf.openSession();
Transaction tx = s.beginTransaction();
User user = new User();
user.setBirthday(new Date());
user.setName("name");
s.save(user);
tx.commit();
s.close();
System.out.println("end");
}
}