JPA辅助表XML配置

时间:2011-07-23 22:44:45

标签: jpa

我正在开发一个项目,我需要存储一个Entity,它是不可修改的(来自库),所以我使用XML实体映射实体对象就像:

public abstract class BaseModel{
    Long uid;
    //getters/setters
}

public abstract class LocaleBaseModel{
    String locale;
    //Other properties, getter/setters
} 

public class Article extends LocaleBaseModel{
    private Long authorId;
    privaet String text;
    //Other properties        
}

<mapped-superclass class="package.BaseModel">
    <attributes>
        <id name="uid">
            <column name="UID" nullable="false" />
            <generated-value strategy="AUTO" />
        </id>
    </attributes>
</mapped-superclass>
<mapped-superclass class="package.LocaleBaseModel">
    <secondary-table name="STableName">
        <primary-key-join-column name="MID" referenced-column-name="UID" />
    </secondary-table>
    <attributes>
        <basic name="locale">
            <column name="LOCALE" updatable="false" nullable="false" />
        </basic>
        <basic name="text">
            <column name="Text" updatable="false" nullable="false" table="STableName" />
        </basic>
    </attributes>
</mapped-superclass>

<entity class="package.child.Article" name="Hadith">
    <table name="TableName" />
    <attributes>

    </attributes>
</entity>

但是一旦我添加<secondarytable>,我就会收到一个错误,这本身就是一个安静的解释:

  
      
  • 14:58:47,379 ERROR ErrorLogger:57 - 解析XML时出错(2):   cvc-complex-type.3.1:元素属性'version'的值'2.0'   'entity-mappings'对应的相应无效   属性使用。属性“version”的固定值为“1.0”。
  •   
  • 14:58:47,379 ERROR ErrorLogger:57 - 解析XML时出错(2):   cvc-complex-type.2.4.a:找到无效的内容   元素'元素集合'。之一   “{“http://java.sun.com/xml/ns/persistence/orm":basic,   “http://java.sun.com/xml/ns/persistence/orm":version,   “http://java.sun.com/xml/ns/persistence/orm":many-to-one,   “http://java.sun.com/xml/ns/persistence/orm":one-to-many,   “http://java.sun.com/xml/ns/persistence/orm":one-to-one,   “http://java.sun.com/xml/ns/persistence/orm":many-to-many,   “http://java.sun.com/xml/ns/persistence/orm":embedded,   预计会有“http://java.sun.com/xml/ns/persistence/orm":transient}”。
  •   
  • 14:58:47,379 ERROR ErrorLogger:57 - 解析XML时出错(2):   cvc-complex-type.2.4.a:找到无效的内容   元素'secondary-table'。之一   “{“http://java.sun.com/xml/ns/persistence/orm":description,   “http://java.sun.com/xml/ns/persistence/orm":id-class,   “http://java.sun.com/xml/ns/persistence/orm":exclude-default-listeners,   “http://java.sun.com/xml/ns/persistence/orm":exclude-superclass-listeners,   “http://java.sun.com/xml/ns/persistence/orm":entity-listeners,   “http://java.sun.com/xml/ns/persistence/orm":pre-persist,   “http://java.sun.com/xml/ns/persistence/orm":post-persist,   “http://java.sun.com/xml/ns/persistence/orm":pre-remove,   “http://java.sun.com/xml/ns/persistence/orm":post-remove,   “http://java.sun.com/xml/ns/persistence/orm":pre-update,   “http://java.sun.com/xml/ns/persistence/orm":post-update,   “http://java.sun.com/xml/ns/persistence/orm":post-load,   预计会有“http://java.sun.com/xml/ns/persistence/orm":attributes}”。
  •   

我已经跟随路径,其他人来自spring 3.0.5

  • 冬眠-的EntityManager-3.6.2
  • 冬眠-JPA-2.0-API
  • hibernate-core-3.6.2.Final

1 个答案:

答案 0 :(得分:0)

根据orm-schema

二级表元素喜欢放置

表标记后的实体元素

<pre> alike &lt;entity>
        &lt;table/>
        &lt;secondary-table/>
        ...

同意错误信息是嘈杂的,但那是 光荣的架构规范。

YS。