Hibernate“一对多,多对一”之配置
Hibernate“一对多,多对一”之配置
?? 假设有两个类:
? 1:图书详情:<多的一方>
?????
public class BookEntity implements Serializable {private int bookId;// 图书编号private BookType bookType;// 图书所属类型private String bookName;// 图书名称}
??? 其xml映射文件如下:
<class table="BookEntity" name="cc.bookims.business.bookentity.model.BookEntity"dynamic-update="true" lazy="false"><id name="bookId" type="integer"><column name="BookId"><comment>"图书--自编号</comment></column><generator type="string"><column name="BookName"><comment>"图书"名称</comment></column></property><many-to-one name="bookType"name="code">public class BookType implements Serializable {private int typeId;// 图书类型编号private String typeName;// 图书类型名private String describes;// 图书类型描述private Set<BookEntity> bookEnts;//图书Set集合}
?其xml映射文件如下:
<class table="BookType" name="cc.bookims.business.booktype.model.BookType"dynamic-update="true" lazy="false"><id name="typeId" type="integer"><column name="TypeId"><comment>"图书类型"自编号</comment></column><generator type="string"><column name="TypeName"><comment>"图书类型"名称</comment></column></property><property name="describes" type="string"><column name="Describes"><comment>"图书类型"描述,说明</comment></column></property><set name="bookEnts" cascade="all" inverse="true"> <!-- TypeId 对应实体BookEntity所映射表中的关联字段 --><key column="TypeId" /><one-to-many /></set></class>
?