hibernate开发步骤
1.导入jar包到WebRoot/WEB-INF/lib文件夹下
2.编写配置文件hibernate.cfg.xml
<hibernate-configuration>
<session-factory>
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="connection.url">jdbc:mysql://127.0.0.1:3306/mysqltest</property>
<property name="connection.username">root</property>
<property name="connection.password">root</property>
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="myeclipse.connection.profile">com.mysql.jdbc.Driver</property>
<property name="show_sql">true</property>
</session-factory>
</hibernate-configuration>
3.创建实体类
303 14.2
package po
public class Student{
private String id;
private String name;
private String subject;
private double result;
public void setId(String id){
this.id=id;
}
public String getId(){
return id;
}
}
4.创建对象关系映射文件 Student.hbm.xml,并且添加到配置文件中
以<mapping>节点配置文件位置
<hibernate-mapping>
<class name="po.Student">
<id name="id"><generator class="assigned" ></generator></id>
<property name="name"></property>
<property name="subject"></property>
<property name="result"></property>
</class>
</hibernate-mapping>
5.创建一个会话工厂类HibernateSessionFactory.java
static{
Configuration configuration.configure("/hibernate.cfg.xml");
SessionFactory sessionfactory=configuration.buildSessionFactory();
Session session=sessionFactory.openSession();
}
6.编写DAO类,里面包含save(),update(),delete(),FindAll()等方法
7.由业务类调用DAO类的方法
1.导入jar包到WebRoot/WEB-INF/lib文件夹下
2.编写配置文件hibernate.cfg.xml
<hibernate-configuration>
<session-factory>
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="connection.url">jdbc:mysql://127.0.0.1:3306/mysqltest</property>
<property name="connection.username">root</property>
<property name="connection.password">root</property>
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="myeclipse.connection.profile">com.mysql.jdbc.Driver</property>
<property name="show_sql">true</property>
</session-factory>
</hibernate-configuration>
3.创建实体类
303 14.2
package po
public class Student{
private String id;
private String name;
private String subject;
private double result;
public void setId(String id){
this.id=id;
}
public String getId(){
return id;
}
}
4.创建对象关系映射文件 Student.hbm.xml,并且添加到配置文件中
以<mapping>节点配置文件位置
<hibernate-mapping>
<class name="po.Student">
<id name="id"><generator class="assigned" ></generator></id>
<property name="name"></property>
<property name="subject"></property>
<property name="result"></property>
</class>
</hibernate-mapping>
5.创建一个会话工厂类HibernateSessionFactory.java
static{
Configuration configuration.configure("/hibernate.cfg.xml");
SessionFactory sessionfactory=configuration.buildSessionFactory();
Session session=sessionFactory.openSession();
}
6.编写DAO类,里面包含save(),update(),delete(),FindAll()等方法
7.由业务类调用DAO类的方法