1、首先在mysql中存在对应的表user,且字段与映射类对应。
package hib;
public class User {
private int id;
private String name;
@Override
public String toString() {
return "user [id=" + id + ", name=" + name + "]";
}
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;
}
}
2、建立hibernate的映射xml(user.hbm.xml)
<?xml version="1.0" encoding="UTF-8"?>3、用hibernate连接数据(hibernate.cfg.xml)
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<!-- 数据库连接的参数配置 -->
<property na