最开始的代码如下:
<?
xml version="1.0" encoding="utf-8"
?>
<!
DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"
>
<!--
Mapping file autogenerated by MyEclipse - Hibernate Tools
-->
<
hibernate-mapping
package
="subselect"
>
<!--
mutable指定Container的只读属性,只能从select中生成
-->
![](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
<
class
name
="Container"
mutable
="false"
>
<
id
name
="id"
unsaved-value
="0"
>
<
generator
class
="native"
></
generator
>
</
id
>
<
property
name
="size"
column
="size"
></
property
>
<
property
name
="name"
column
="name"
></
property
>
<
property
name
="description"
column
="description"
></
property
>
<
property
name
="xparam"
column
="xparam"
></
property
>
<
property
name
="yparam"
column
="yparam"
></
property
>
<
property
name
="zparam"
column
="zparam"
></
property
>
<
subselect
>
select id,size,name,description,diameter as xparam,diameter as yparam,height as zparam from Bottle
union
select id,size,name,description,width as xparam,length as yparam,height as zparam from Box
</
subselect
>
<
synchronize
table
="Box"
/>
<
synchronize
table
="Bottle"
/>
</
class
>
</
hibernate-mapping
>
可不知道为什么,class标签旁边总有个小红叉叉,但是在IE中又能正常显示这个xml
最后发现,原来是标签的前后顺序有问题,<synchronize>和<subselect>标签要放在<id>标签前面
并且<subselect>标签要在<synchronize>标签前面
修改后的代码如下:
<?
xml version="1.0" encoding="utf-8"
?>
<!
DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"
>
<!--
Mapping file autogenerated by MyEclipse - Hibernate Tools
-->
<
hibernate-mapping
package
="subselect"
>
<!--
mutable指定Container的只读属性,只能从select中生成
-->
![](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
<
class
name
="Container"
mutable
="false"
>
<
subselect
>
select id,size,name,description,diameter as xparam,diameter as yparam,height as zparam from Bottle
union
select id,size,name,description,width as xparam,length as yparam,height as zparam from Box
</
subselect
>
<
synchronize
table
="Box"
/>
<
synchronize
table
="Bottle"
/>
<
id
name
="id"
unsaved-value
="0"
>
<
generator
class
="native"
></
generator
>
</
id
>
<
property
name
="size"
column
="size"
></
property
>
<
property
name
="name"
column
="name"
></
property
>
<
property
name
="description"
column
="description"
></
property
>
<
property
name
="xparam"
column
="xparam"
></
property
>
<
property
name
="yparam"
column
="yparam"
></
property
>
<
property
name
="zparam"
column
="zparam"
></
property
>
</
class
>
</
hibernate-mapping
>