Hibernate:多个父对象到子对象的映射

Hibernate:多个父对象到子对象的映射,hibernate,Hibernate,我有以下java类: Class Table1 { Integer id; Set<Error> errors; } Class Table2 { Integer id; Set<Error> errors; } Class Table3 { Integer id; Set<Error> errors; } Class Error { Integer id; Integer tableId; //

我有以下java类:

Class Table1 
{  Integer id; 
   Set<Error> errors;
}
Class Table2
{  Integer id;  
   Set<Error> errors;
}
Class Table3
{ Integer id;   
  Set<Error> errors;
}

Class Error
{  
    Integer id;  
    Integer tableId;  // Pk of parent id  
    String tableName;  
    String errorMessage
}
请帮我做正确的映射


谢谢

任何映射都适用于此处

Class Table1 implements HasErrors
{  Integer id; 
   Set<Error> errors;
}
Class Table2 implements HasErrors
{  Integer id;  
   Set<Error> errors;
}
Class Table3 implements HasErrors
{ Integer id;   
  Set<Error> errors;
}

Class Error
{  
    Integer id;  
    HasErrors parent;
    String errorMessage
}

    Integer tableId;  // Pk of parent id  
    String tableName;  

<class name="Error" table="ERROR" schema="XXX" catalog="xxxxx">
    ...
    <any name="parent" id-type="integer" meta-type="String">
      <meta-value value="Table1" class="Table1"/>
      <meta-value value="Table2" class="Table2"/>
      <column name="TABLE_NAME"/>
      <column name="TABLE_ID"/>
    </any>    
    <property name="errorMessage" type="string">
        <column name="ERROR_MESSAGE" length="100" />
    </property>
</class>

<class name="Table1" table="TABLE1" schema="xxx" catalog="XXXXX">
    ...
    <set name="errors" table="ERROR" lazy="false" cascade="all-delete-orphan" where="TABLE_NAME='table1'">
      <key column ="TABLE_ID" not-null="true" />
      <many-to-any id-type="integer" meta-type="String">
        <meta-value value="Table1" class="Table1"/>
        <meta-value value="Table2" class="Table2"/>
        <column name="TABLE_NAME" not-null="true"/>
        <column name="TABLE_ID" not-null="true"/>
      </many-to-any>
    </set>
</class>
类Table1实现了HasErrors
{整数id;
设置错误;
}
类Table2实现了HasErrors
{整数id;
设置错误;
}
类Table3实现了HasErrors
{整数id;
设置错误;
}
类错误
{  
整数id;
有错误的父母;
字符串错误消息
}
整数tableId;//父id的主键
字符串表名;
...
...

您能否显示给您错误的映射?当我将表2的映射与表1相同,只是将表1替换为表2时,我得到了此错误。谢谢。嗨,菲罗,谢谢你的回复。我尝试了此映射,但出现了以下错误:org.hibernate.MappingException:无法解释元值。能否请您详细说明或指向一些文档以供使用?接口有哪些方法?我试图将来自不同表(7)的错误存储在一个带有鉴别器“table Name”的错误表中。谢谢。嗨,菲罗,谢谢你的链接。我没有得到多少帮助。我仍然无法找出子表映射上的错误:rg.hibernate.MappingException:无法解释元值。你能给我指一下正确的方向吗。谢谢。完整的stacktrace会有帮助的。我认为应该有一个内在的例外
<hibernate-mapping>
<class name="Error" table="ERROR" schema="XXX" catalog="xxxxx">
    <id name="id" type="integer">
        <column name="ID" />
        <generator class="native" />
    </id>
    <version column="MODIFIED_DATE" name="modifiedDate" type="timestamp" unsaved-value="null"/>
    <property name="tableId" type="integer" insert="false" update="false" >
        <column name="TABLE_ID" not-null="true" />
    </property>
    <property name="tableName" type="string">
        <column name="TABLE_NAME" not-null="true" length="20" />
    </property>
    <property name="errorMessage" type="string">
        <column name="ERROR_MESSAGE" length="100" />
    </property>
</class>
org.hibernate.MappingException: Repeated column in mapping for entity: Error column:
         TABLE_ID (should be mapped with insert="false" update="false")
Class Table1 implements HasErrors
{  Integer id; 
   Set<Error> errors;
}
Class Table2 implements HasErrors
{  Integer id;  
   Set<Error> errors;
}
Class Table3 implements HasErrors
{ Integer id;   
  Set<Error> errors;
}

Class Error
{  
    Integer id;  
    HasErrors parent;
    String errorMessage
}

    Integer tableId;  // Pk of parent id  
    String tableName;  

<class name="Error" table="ERROR" schema="XXX" catalog="xxxxx">
    ...
    <any name="parent" id-type="integer" meta-type="String">
      <meta-value value="Table1" class="Table1"/>
      <meta-value value="Table2" class="Table2"/>
      <column name="TABLE_NAME"/>
      <column name="TABLE_ID"/>
    </any>    
    <property name="errorMessage" type="string">
        <column name="ERROR_MESSAGE" length="100" />
    </property>
</class>

<class name="Table1" table="TABLE1" schema="xxx" catalog="XXXXX">
    ...
    <set name="errors" table="ERROR" lazy="false" cascade="all-delete-orphan" where="TABLE_NAME='table1'">
      <key column ="TABLE_ID" not-null="true" />
      <many-to-any id-type="integer" meta-type="String">
        <meta-value value="Table1" class="Table1"/>
        <meta-value value="Table2" class="Table2"/>
        <column name="TABLE_NAME" not-null="true"/>
        <column name="TABLE_ID" not-null="true"/>
      </many-to-any>
    </set>
</class>