现在又一个pojo
class Student{
int id ;
String name;
Birthday birthday;
//geter setter}class Birthday { Date year;
Date month;
Date day; //geter setter
}表 id int 10 主键
name vachar 10
year date 10
month date 10
day date 10这时候mapping文件如何写,属于关联映射吗?
class Student{
int id ;
String name;
Birthday birthday;
//geter setter}class Birthday { Date year;
Date month;
Date day; //geter setter
}表 id int 10 主键
name vachar 10
year date 10
month date 10
day date 10这时候mapping文件如何写,属于关联映射吗?
<hibernate-mapping package="pojo"> <class name="student" table="student">
<id name="id" column="id">
<generator class="native"></generator>
</id>
<property name="name" type="java.lang.String"></property>
<many-to-one name="birthday" column="birthdayId"
class="Brithday">
</many-to-one>
</class>
</hibernate-mapping>
Birthday.hbm.xml
<hibernate-mapping
package="pojo"> <class name="Brithday" table="Birthday">
<id name="birthdayId">
<generator class="native"></generator>
</id>
<property name="year" type="java.sql.Date"></property>
<property name="month" type="java.sql.Date"></property>
<property name="day" type="java.sql.Date"></property>
</class>
</hibernate-mapping>
然后在hibernate主配置文件中引入即可
只有一个student表,Birthday没有表
hibernate 是一个vo对应一个表,你写两个vo不就2张, 你想一张表就把字段放在一个vo里面
<id name="id" column="pid" type="string">
<generator class="native"/>
</id>
<property name="name" type="string"/>
<component name="Birthday" class="Birthday"> <!-- class attribute optional -->
<property name="year"/>
<property name="month"/>
<property name="day"/>
</component>
</class>
大概就是这个样子