hibernate的配置步骤:
-导入相关的jar包
下载网站: http://sourceforge.net/projects/hibernate/files/
文件目录:
-添加配置文件 hibernate.cfg.xml
<hibernate-configuration>
<session-factory >
<property name="hibernate.dialect">org.hibernate.dialect.MySQLInnoDBDialect</property>
<property name="hibernate.connection.driver_class ">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/hibernateTest</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.connection.password"> </property>
<property name="show_sql">true</property>
<mapping resource="cn/hrbust/pojo/User.hbm.xml"/>
</session-factory>
</hibernate-configuration>
-创建user.hdm.xml
<?xml version="1.0"?>
<hibernate-mapping package="com.allwinter.pojo">
<class name="User" table="t_user">
<id name="id" column="id">
<generator class="native"/>
</id>
<property name="name" column="name"/>
<property name="age" column="age"/>
</class>
</hibernate-mapping>
-创建实体类
package com.zhangyi.po;
import java.sql.Date;
public class User {
private int id;
private String name;
private String gender;
int age;
Date birthday;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getGender() {
return gender;
}
public void setGender(String gender) {
this.gender = gender;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public Date getBirthday() {
return birthday;
}
public void setBirthday(Date birthday) {
this.birthday = birthday;
}
}
-创建表
要注意mysql5.0与8.0的不同,以及url的不同写法:
-idea中连接database