3. 手动创建Hibernate
- 创建Hibernate映射关系,我们需要创建三个文件:
1.1 第一个是实体类Class
public class Cat(){
private Integer catKeyid;
private String name;
private Integer age;
private Cat Child;
private boolean isDead;
...
...
get() and set() method of attr.
...
}
1.2 创建SQL中的table-cat,把相应的属性创建出来 1.3 创建映射文件-Cat.hbm.xml
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="model.Cat" table="cat">
<id name="catKeyid" type="java.lang.Integer">
<column name="cat_keyid" />
<generator class="identity" />
</id>
<many-to-one name="child" class="model.Cat" fetch="select">
<column name="cat_keyid" not-null="true" />
</many-to-one>
<property name="name" type="java.lang.String">
<column name="name" />
</property>
<property name="age" type="java.lang.Integer">
<column name="age" />
</property>
<property name="isDead" type="byte">
<column name="is_dead" not-null="true" />
</property>
</class>
</hibernate-mapping>
|