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