一个十分诡异的Hibernate Mapping文件XML校验错误

本文解决了Hibernate XML映射文件中因元素顺序不当导致的问题,调整了<synchronize>和<subselect>的位置,并确保<subselect>位于<synchronize>之前且二者都在<id>标签前。

最开始的代码如下:

 

<?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中生成 -->

  
  
<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中生成 -->

  
  
<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>
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值