0

在我的应用程序中,我在一个表中没有主键列。我将其视为代理键并尝试使用标记。但我遇到了异常。

**"org.hibernate.MappingException: Error reading resource:     
    com/mapping/FamilyDetails.hbm.xml"**

**Caused by: org.xml.sax.SAXParseException: 
    The content of element type "class" must match "
    (meta*,subselect?,cache?,synchronize*,comment?,
    (id|composite-id),discriminator?,natural-id?,(version|timestamp)?,
    (property|many-to-one|one-to-one|component|dynamic-
    component|properties|any|map|set|list|bag|idbag|array|
    primitive-array|query-list)*,
    ((join*,subclass*)|joined-subclass*|union-subclass*),loader?,
    sql-insert?,sql-update?,sql-delete?,filter*)".**

映射文件:-FamilyDetails.hbm.xml

<class name="com.beans.FamillyDetails" 
       table="personal_fmly_dtls" proxy="com.aims.beans.FamillyDetails">


    <natural-id>
        <property name="systemid" />
    </natural-id>
    <property name="membername" 
              type="java.lang.String" column="membername" not-null="true" />
    <property name="relation"  
              type="java.lang.String" column="relation" not-null="true" />
    <property name="dateOfBirth"  
              type="java.util.Date" column="dateofbirth" not-null="true" />

    <many-to-one name="Personal" column="pid" class="com.aims.beans.Personal"/>

</class>



<?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" >
<hibernate-mapping>
<class name="com.aims.beans.Personal" 
       table="personalinfo" proxy="com.aims.beans.Personal">

<id name="pid" column="pid" type="java.lang.Integer">
    <generator class="sequence">
        <param name="sequence">personal_seq</param>
    </generator>
</id>
<property name="name"  
          type="java.lang.String" column="name" not-null="true" />
<property name="deptno"  
          type="java.lang.Integer" column="DEPTNO" not-null="true" />

<component name="permentaddress" class="com.aims.beans.Address">
    <property name="homeAddress1" type="java.lang.String" column="pddress1"/>
    <property name="homeAddress2" type="java.lang.String" column="pddress2"/>
    <property name="homecity"     type="java.lang.String" column="pcity"/>
    <property name="homeState"    type="java.lang.String" column="pstate"/>
</component>
<set name="famildtlslst">
    <key column="pid" not-null="true"/>
    <one-to-many class="com.aims.beans.FamillyDetails"/>
</set>
<join table="address">     
    <key column="pid" /> 
    <component name="Address" class="com.aims.beans.Address">
        <property name="homeAddress1" 
                  type="java.lang.String" column="HomeAddress1"/>
        <property name="homeAddress2" 
                  type="java.lang.String" column="HomeAddress2"/>
        <property name="homecity" 
                  type="java.lang.String" column="homecity"/>
        <property name="homeState" 
                  type="java.lang.String" column="homestate"/>
    </component>
</join>

请帮我。

4

1 回答 1

2

它可能是另一个组件。组件不需要主键:

<set name="famildtlslst" table="personal_fmly_dtls">
  <key column="pid" not-null="true"/>
  <composite-element parent="Personal">
    <property name="systemid" />
    <property name="membername" not-null="true" />
    <property name="relation" not-null="true" />
    <property name="dateOfBirth" not-null="true" />
  </composite-element>
</set>

当然,这是另一种语义,但如果您对组件感到满意,那就更容易了。

于 2012-07-06T12:44:56.917 回答