-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 
Author Message
 Post subject: Can't map child List w/ composite ID
PostPosted: Fri Jan 20, 2006 2:38 pm 
Regular
Regular

Joined: Mon Nov 14, 2005 7:33 pm
Posts: 73
I've got a parent/child relationship where both tables/classes have a composite ID.

Both of the objects can be queried individually w/o error but I have problems when I try to create the parent/child relationship in the mapping.

I am getting this exception message:

Code:
11:25:50,154  INFO Configuration:468 - Reading mappings from resource: PactsSalesHeader.hbm.xml
11:25:50,184 ERROR XMLHelper:61 - Error parsing XML: XML InputStream(25) Attribute "insert" must be declared for element type "column".
11:25:50,195 ERROR XMLHelper:61 - Error parsing XML: XML InputStream(25) Attribute "update" must be declared for element type "column".
11:25:50,245 ERROR XMLHelper:61 - Error parsing XML: XML InputStream(26) Attribute "insert" must be declared for element type "column".
11:25:50,245 ERROR XMLHelper:61 - Error parsing XML: XML InputStream(26) Attribute "update" must be declared for element type "column".
11:25:50,245 ERROR HibernateUtil:79 - Building SessionFactory failed.
org.hibernate.MappingException: Could not read mappings from resource: PactsSalesHeader.hbm.xml


However, I've done what it is telling me to do...as you can see below in my mapping files...

parent:

Code:
<hibernate-mapping>
   <class
      name="PactsSalesHeader"
      proxy="PactsSalesHeader"
      table="pa_invhdrp">
     <composite-id name="Id" class="PactsSalesHeaderId">
      <key-property name="InvoiceNumber" column="ihinvno" />
         <key-property name="CompanyCode" column="comcode" />
    </composite-id>
     <property name="BranchId" column="brid"/>
      <property name="DateCreated" column="ihcrtdte"/>
      <property name="InvoiceTotal" column="ihinvtot"/>
     <bag
        name="Branches"
        table="pa_branchp"
         inverse="true"
        lazy="true"
        fetch="select"
        cascade="none">
        <key>
            <column name="brid" insert="false" update="false" />
            <column name="comcode" insert="false" update="false" />
        </key>
        <one-to-many class="PactsBranch" />
     </bag>
   </class>
</hibernate-mapping>


child:

Code:
<hibernate-mapping>
   <class
      name="PactsBranch"
      proxy="PactsBranch"
      table="pa_branchp">
     <composite-id name="Id" class="PactsBranchId">
      <key-property name="BranchId" column="brid" />
         <key-property name="CompanyCode" column="comcode" />
    </composite-id>
     <property name="Name" column="brname"/>
     <many-to-one
        name="Header"
         insert="false"
         update="false"
        class="PactsSalesHeader">
         <column name="ihinvno" insert="false" update="false" />
         <column name="comcode" insert="false" update="false" />
      </many-to-one>
   </class>
</hibernate-mapping>


Where do I go from here? I could not find a post in the forums that would clear this issue up for me...and I'm following the exact instructions from Hibernate In Action on how to do this...yet something is wrong.

Please advise! Thanks!

Hibernate version: 3.1

Name and version of the database you are using: MSSQL 2000


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 20, 2006 3:58 pm 
Beginner
Beginner

Joined: Fri Oct 28, 2005 12:26 pm
Posts: 21
Here's one of my mapping files with composite keys. Does this help?

Code:
<?xml version="1.0"?>
<!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.idex.processtracking.bean.GroupMember" table="GroupMembers">
    <cache usage="read-write" />
    <composite-id>
      <key-many-to-one name="user" class="com......User"
          column="userName" />
      <key-many-to-one name="group" class="com.......Group"
          column="groupName" />
    </composite-id>
  </class>
</hibernate-mapping>


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 20, 2006 4:02 pm 
Beginner
Beginner

Joined: Fri Oct 28, 2005 12:26 pm
Posts: 21
As long as I posted that, here's the other end of the relationship. Remember to make this one inverse.

<?xml version="1.0"?>
<!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.User" table="Users">
<cache usage="read-write" />
<id column="userName" name="userName" type="string">
<generator class="assigned" />
</id>
<many-to-one name="businessUnit" column="buName" cascade="save-update"
class="com.BusinessUnit" />
<property name="enabled" column="enabled" type="boolean" not-null="true"/>
<property name="firstName" column="firstName" type="string"
not-null="true"/>
<property name="lastName" column="lastName" type="string" not-null="true"/>
<property name="address" column="address" type="string"/>
<property name="city" column="city" type="string"/>
<property name="state" column="state" type="string"/>
<property name="zip" column="zip" type="string"/>
<property name="country" column="country" type="string"/>
<property name="phone" column="phone" type="string"/>
<property name="mobile" column="mobile" type="string"/>
<property name="email" column="email" type="string" not-null="true"
unique="true" />
<set name="groupMemberships" inverse="true" cascade="all-delete-orphan"
lazy="true">
<cache usage="read-write" />
<key column="userName" />
<one-to-many class="com.GroupMember" />
</set>
</class>
</hibernate-mapping>


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 20, 2006 4:15 pm 
Regular
Regular

Joined: Mon Nov 14, 2005 7:33 pm
Posts: 73
hmm...sorry, can't see where that helps.

Everything works except the <bag> mapping on mine and yours does not contain a collection w/ a composite key, like mine does.

If I take the <bag> mapping out I can pull records...it works fine...but I'm obviously doing something wrong in the child collection mapping.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 20, 2006 7:54 pm 
Regular
Regular

Joined: Mon Nov 14, 2005 7:33 pm
Posts: 73
OK, got rid of the errors and am joining the two tables together but the join is wrong...but that's for another thread.

Thanks!


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.