1.实体bean设计
car:
public class Car { private int id; private String name; private Wheel wheel; set... get... }
wheel:
public class Wheel { private int count; private int size; set... get... }
2.配置映射文件
<?xml version="1.0" encoding="utf-8" ?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd"> <hibernate-mapping package="com.juaner.hibernate.compositeMap"> <class name="Car" table="t_car"> <!--主键--> <id name="id"> <generator class="native"/> </id> <property name="name" length="25" type="string"/> <!--映射到一张表中--> <component name="wheel"> <property name="size"/> <property name="count"/> </component> </class> </hibernate-mapping>
生成的数据表: