有的时候如果多个表互相关联,需要创建视图,如果想用Hibernate查询视图的数据怎么办呢?其实视图和表没有本质的区别,只需要把主键换为组合主键即可,例如:
<?xml version="1.0" ?>
<!DOCTYPE hibernate-mapping
PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="org.gamestore.bo.GameView" table="GS_GAME_VIEW" lazy="false">
<composite-id>
<key-property name="subGameId" column="ID" type="long"/>
<key-property name="mainGameId" column="MAINGAME_ID" type="long"/>
</composite-id>
<property name="nameCn" type="string" column="NAMECN" />
<property name="nameEn" type="string" column="NAMEEN" />
</class>
</hibernate-mapping>