休眠!实体

问题描述:

此网页建议!ENTITY:
$ b

This page suggests !ENTITY:


如果您想避免重复,请考虑使用XML实体(对于
示例,[]
DOCTYPE声明和%allproperties;在映射中)。

If you want to avoid duplication, consider using XML entities (for example, [ ] in the DOCTYPE declaration and %allproperties; in the mapping).

问题是我找不到任何地方网上一个完整的工作示例。

The problem is that I can't find anywhere on the web a complete working example.

到目前为止,我得到的是:

What I got so far is:

<!DOCTYPE hibernate-mapping PUBLIC
        "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
        "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd"
        [ <!ENTITY allproperties SYSTEM "allproperties.xml"> ]
        >

..但其他情况如何?

1.如何确切地做我在 allproperties.xml 文件中定义了属性?
2.如何/在哪里包含%allproperties ; 关键字(在我的< class> < union-class> 中) ?

.. but what about the rest?
1. How EXACTLY do I define the properties in the allproperties.xml file?
2. How/Where EXACTLY do I include the %allproperties; keyword (within my <class> and <union-class>)?

这是一个称为实体include的基本XML构造。名为'allproperties.xml'的文件将包含实体的属性映射片段。例如:

This is a basic XML construct called an entity include. You file named 'allproperties.xml' would contain the property mapping fragments of the entities. For example:

<property name="name".../>
<property name="someOtherProperty".../>
<!-- rest of shared property definitions -->

然后在映射文件中,您会说:

Then in a mapping file you'd say:

<!DOCTYPE hibernate-mapping PUBLIC
    "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
    "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd" [ 
    <!ENTITY allproperties SYSTEM "allproperties.xml"> ]>

<hibernate-mapping>
    <class name="Class1" ...>
        <id .../>
        &allproperties;
    </class>
    <class name="Class2" ...>
        <id .../>
        &allproperties;
    </class>
</hibernate-mapping>

我定义了< id /> 映射到这里的每个类中,但是如果信息完全相同,也可以将它移动到包含文件中。任何作为< class /> 的孩子有效的内容都可以在包含文件中使用。

I defined the <id/> mapping in each class here, but you can move that into the include file as well if the information is all the same. Anything that is valid as a child of <class/> will work in the include file.

JAXP期望SYSTEM引用是相对或绝对文件引用。因此,以上意味着allproperties.xml文件将相对于包含文件的系统标识符进行解析。通常情况下,这可能无法奏效。为此,Hibernate还了解了一个特殊类型的以classpath://为前缀的SYSTEM引用。正如你所期望的那样,为所引用的资源触发类路径资源查找。

JAXP expects SYSTEM references to be relative or absolute file references. So above means that the allproperties.xml file would be resolved relative to system identifier of the include file. Often that might not work out so well. To that end, Hibernate also understands a special type of SYSTEM reference prefixed with classpath://. As you might expect that triggers a classpath resource lookup for the referenced resource.

<!DOCTYPE hibernate-mapping PUBLIC
        "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
        "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd" [ 
    <!ENTITY allproperties SYSTEM "classpath://com/acme/allproperties.xml"> ]>

现在,allproperties.xml将通过使用com / acme / allproperties.xml的类路径查找来解析资源名称。

Now, allproperties.xml will be resolved via a classpath lookup using the com/acme/allproperties.xml resource name.