hbm.xml插入外部xml文件的配置

hbm.xml可插入外部xml文件替换重复使用的内容。例如我这里对User进行分表,将使用user0user1user2之类的表,因此hbm映射文件内容基本都是一样的。可使用ENTITY声明插入外部的xml片段。

dbmap/User.hbm.xml

<?xml version="1.0"?>

<!DOCTYPE hibernate-mapping PUBLIC

    "-//Hibernate/Hibernate Mapping DTD 3.0//EN"

    "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"

    [<!ENTITY UserProperty SYSTEM "classpath://dbmap/UserProperty.xml">]>

 

 

<hibernate-mapping package="model">

    <class

        name="User0"

        table="user0"

        lazy="false"

    >

        &UserProperty;

    </class>   

   

    <class

        name="User1"

        table="user1"

        lazy="false"

    >

        &UserProperty;

    </class>

</hibernate-mapping>

hibernate3.2以上版本支持ENTITY使用classpath://协议。

如果classpath://dbmap/UserProperty.xml这个路径找不着文件,会报出一个很让人误解的异常:

org.dom4j.DocumentException: unknown protocol: classpath Nested exception

应该提示路径找不到,而不是提示不支持这个协议。

 

其中dbmap/UserProperty.xml

<?xml encoding="utf-8"?>

<id

    name="id"

    type="string"

    column="id"

    <generator class="assigned"/>

</id>

 

<property

    name="name"

    column="name"

    type="string"

    not-null="false"

    length="20"

/>

<property

    name="passwd"

    column="passwd"

    type="string"

    not-null="false"

    length="20"

/>

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值