開始Hibernate:
對於該Table建立一個對應的test.com.hbm.User.hbm.xml:
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> <hibernate-mapping> <class name="test.com.model.UserModel" table="user"> <id column="id" name="id" type="java.lang.Integer"> <generator class="native"/> </id> <property column="name" name="name" type="java.lang.String"/> <property column="age" name="age" type="java.lang.String"/> </class> </hibernate-mapping>
|
package test.com.model; import java.io.Serializable; public class UserModel implements Serializable { //ID private Integer id; //姓名 private String name; //年齡 private String age; public String getAge() { return age; } public void setAge(String age) { this.age = age; } public Integer getId() { return id; } public void setId(Integer id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } } |
<hibernate-configuration> <session-factory> ………………………. <!-- 以下設置物件與資料庫表格映射文件 --> <mapping resource="test/com/hbm/User.hbm.xml"/> </session-factory> </hibernate-configuration> |
留言列表