-->
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.  [ 3 posts ] 
Author Message
 Post subject: collection element mapping has wrong number of columns
PostPosted: Mon Aug 14, 2006 2:09 pm 
Newbie

Joined: Mon Jan 09, 2006 11:12 am
Posts: 6
Hibernate version:3.0.5

I am getting an exception for hibernate mapping
Quote:
exception collection element mapping has wrong number of columns


Following is an example:

I have two tables -- table A and table B

Table A

C1, C2, C3, C4, C5, C6, C7 (NON-UNIQUE INDEX)

C8 thru C20 (rest of the columns on the table)

Table B

C1, C2, C3, C4, C5, C6, C7 (NON-UNIQUE INDEX)

C8 thru C40 (rest of the columns on the table)

My Object Mapping files:

I have created a separate class for column C1 thru C7, called RecordId

Code:
public class RecordId implements Serializable {

   private String c1 = null;   
   private String c2 = null;
   private String c3 = null;
   private String c4 = null;   
   private String c5 = null;
   private String c6 = null;
   private String c7 = null;

along with getters and setters

}


Code:
public class ClassA implements java.io.Serializable
{
   
   private RecordId recordId;
   
   private java.lang.String c8 = "";
   private java.lang.String c20 = "";

}


Code:
public class ClassB implements java.io.Serializable
{
   
   private RecordId recordId;
   
   private java.lang.String c8 = "";
   private java.lang.String c40 = "";

}


HBM mapping files:

Class A

Code:
<class
    name="ClassA"
    table="TableA"
>

    <composite-id name = "id" class = "RecordId">

        <key-property
            name="C1"
            column="COL1"
            type="java.lang.String"
            length="18"
        />

        <key-property
            name="C2"
            column="COL2"
            type="java.lang.String"
            length="7"
        />

        <key-property
            name="C3"
            column="COL3"
            type="java.lang.String"
            length="8"
        />


        <key-property
            name="C4"
            column="COL4"
            type="java.lang.String"
            length="5"
        />

        <key-property
            name="C5"
            column="COL5"
            type="java.lang.String"
            length="2"
        />

        <key-property
            name="C6"
            column="COL6"
            type="java.lang.String"
            length="7"
        />

        <key-property
            name="C7"
            column="COL7"
            type="char"
            length="1"
        />

    </composite-id>

   <property name="recordId" insert="false" update="false" access="field"/>

   <bag name="ClassBTransactions"  table="TableA">
      <key property-ref="recordId" />      
      <many-to-many class="ClassB" column="recordId"></many-to-many>
   </bag>

    <property
            name="C8"
            column="COL8"
            type="java.lang.String"
            length="26"
        />


Class B

Code:
<class
    name="ClassB"
    table="TableB"
>

    <composite-id name = "id" class = "RecordId">

        <key-property
            name="C1"
            column="COL1"
            type="java.lang.String"
            length="18"
        />

        <key-property
            name="C2"
            column="COL2"
            type="java.lang.String"
            length="7"
        />

        <key-property
            name="C3"
            column="COL3"
            type="java.lang.String"
            length="8"
        />


        <key-property
            name="C4"
            column="COL4"
            type="java.lang.String"
            length="5"
        />

        <key-property
            name="C5"
            column="COL5"
            type="java.lang.String"
            length="2"
        />

        <key-property
            name="C6"
            column="COL6"
            type="java.lang.String"
            length="7"
        />

        <key-property
            name="C7"
            column="COL7"
            type="char"
            length="1"
        />

    </composite-id>

   <property name="recordId" insert="false" update="false" access="field"/>

   <bag name="ClassATransactions"  table="TableA">
      <key property-ref="recordId" />      
      <many-to-many class="ClassA" column="recordId"></many-to-many>
   </bag>

    <property
            name="C8"
            column="COL8"
            type="java.lang.String"
            length="26"
        />



Code:
public class RecordId implements Serializable {

   private String c1 = null;   
   private String c2 = null;
   private String c3 = null;
   private String c4 = null;   
   private String c5 = null;
   private String c6 = null;
   private String c7 = null;

along with getters and setters

}


Am I doing something wrong (syntax wise) with the mappings?

Thanks.


Abhijit


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 14, 2006 5:14 pm 
Expert
Expert

Joined: Tue Apr 25, 2006 12:04 pm
Posts: 260
Code:
public class RecordId implements Serializable {

   private String c1 = null;   
   private String c2 = null;
   private String c3 = null;
   private String c4 = null;   
   private String c5 = null;
   private String c6 = null;
   private String c7 = null;

   //along with getters and setters

}


Code:
public class ClassA extends RecordId
{
   // I dont need this element anymore
   //private RecordId recordId;
   
   private java.lang.String c8 = "";
   private java.lang.String c20 = "";

}


Code:
public class ClassB extends RecordId
{
   // I dont need this element anymore
   //private RecordId recordId;
   
   private java.lang.String c8 = "";
   private java.lang.String c40 = "";

}


With above setup remove the element

Code:
<property name="recordId" ... />


and try to see if it works.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 16, 2006 5:09 pm 
Newbie

Joined: Mon Jan 09, 2006 11:12 am
Posts: 6
Ok, I tried working on your suggestion, however I am getting an Exception

Foreign key (FK23FA6D682F41683:TableB [elt])) must have same number of columns as the referenced primary key

My code now looks like this

Code:
<bag name="classB" table="TableB">
   <key>
      <column name ="C1"/>
      <column name="C2" />
      <column name="C3" />
      <column name="C4" />
      <column name="C5" />
      <column name="C6" />
      <column name="C7" />
   </key>         
   <many-to-many
      class="ClassB">
   </many-to-many>
</bag>


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.