-->
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.  [ 6 posts ] 
Author Message
 Post subject: Mapping Exception
PostPosted: Tue Aug 30, 2005 6:49 am 
Newbie

Joined: Tue Aug 30, 2005 5:56 am
Posts: 2
Hibernate version: 2.1.2
Oracle 9.2


PROBLEM

Before looking at the actual Error Exception, a brief on Database structure and some Code

There are two database tables involved.
1. ImsTable
IMS_ID and Version are Composite Keys

2. ImsSpecTable
IMS_DOCID, IMS_FIELD1 and IMS_FILED2 are Composite Keys

For relation between the above two tables please refer to the HBM mapping files after the Error description below.

The Error is generated because I try to Insert a record into database table ImsTable

Here is the insertion code------------------------------------------------------------------------
ImsTablePK comp_id= new ImsTablePK();
comp_id.setImsId(new Long(1));
comp_id.setVersion(new Integer(1));

ImsTable obj = new ImsTable();
obj.setComp_id(comp_id);
obj.setImsAdr("address");
obj.setImsAdrArchive("addr Archive");
obj.setImsAno("Y");
obj.setImsCasIdRef("id ref");
obj.setImsEnhance("E");
obj.setImsHeader("ims header");
obj.setImsMaster("ims master");
obj.setImsPages(new Long(10));
obj.setImsStart(new Long(10));
obj.setImsType("type");

imsDao = new ImsTableDAO();

try{
imsDao.save(obj);
imsDao = null;
}
catch(Exception e){
System.out.println("Exception in Ims Table \n"+e);
}

------------------------------------------------------------------------


The Exception. Below is a complete Log trace

-------------------------------------------------------------------------------------
INFO cfg.Environment - Hibernate 2.1.2
INFO cfg.Environment - loaded properties from resource hibernate.properties: {hibernate.connection.driver_class=oracle.jdbc.driver.OracleDriver, hibernate.cglib.use_reflection_optimizer=true, hibernate.dialect=net.sf.hibernate.dialect.Oracle9Dialect, hibernate.generate_statistics=true, hibernate.connection.username=temptoadm, hibernate.connection.url=jdbc:oracle:thin:@10.25.115.195:1521:imadb9, hibernate.show_sql=true, hibernate.connection.password=admtempto, hibernate.statement_cache.size=100, hibernate.connection.pool_size=10}
INFO cfg.Environment - using CGLIB reflection optimizer
Classes: - class com.tsystems.ecm.imaes.imadb.hibernate2.archive.ImsTable
INFO cfg.Configuration - Mapping resource: com/tsystems/ecm/imaes/imadb/hibernate2/archive/ImsTable.hbm.xml
DEBUG util.DTDEntityResolver - trying to locate http://hibernate.sourceforge.net/hibern ... ng-2.0.dtd in classpath under net/sf/hibernate/
DEBUG util.DTDEntityResolver - found http://hibernate.sourceforge.net/hibern ... ng-2.0.dtd in classpath
INFO cfg.Binder - Mapping class: com.tsystems.ecm.imaes.imadb.hibernate2.archive.ImsTable -> IMS_TABLE
DEBUG cfg.Binder - Mapped property: imsId -> IMS_ID, type: long
DEBUG cfg.Binder - Mapped property: version -> VERSION, type: integer
DEBUG cfg.Binder - Mapped property: comp_id -> IMS_ID, VERSION, type: com.tsystems.ecm.imaes.imadb.hibernate2.archive.ImsTablePK
DEBUG cfg.Binder - Mapped property: imsType -> IMS_TYPE, type: string
DEBUG cfg.Binder - Mapped property: imsAno -> IMS_ANO, type: string
DEBUG cfg.Binder - Mapped property: imsStart -> IMS_START, type: long
DEBUG cfg.Binder - Mapped property: imsPages -> IMS_PAGES, type: long
DEBUG cfg.Binder - Mapped property: imsEnhance -> IMS_ENHANCE, type: string
DEBUG cfg.Binder - Mapped property: imsMaster -> IMS_MASTER, type: string
DEBUG cfg.Binder - Mapped property: imsCasIdRef -> IMS_CAS_ID_REF, type: string
DEBUG cfg.Binder - Mapped property: imsAdr -> IMS_ADR, type: string
DEBUG cfg.Binder - Mapped property: imsAdrArchive -> IMS_ADR_ARCHIVE, type: string
DEBUG cfg.Binder - Mapped property: imsHeader -> IMS_HEADER, type: string
DEBUG cfg.Binder - Mapped property: archiveFiles, type: java.util.Set
Classes: - class com.tsystems.ecm.imaes.imadb.hibernate2.archive.ImsSpecTable
INFO cfg.Configuration - Mapping resource: com/tsystems/ecm/imaes/imadb/hibernate2/archive/ImsSpecTable.hbm.xml
DEBUG util.DTDEntityResolver - trying to locate http://hibernate.sourceforge.net/hibern ... ng-2.0.dtd in classpath under net/sf/hibernate/
DEBUG util.DTDEntityResolver - found http://hibernate.sourceforge.net/hibern ... ng-2.0.dtd in classpath
INFO cfg.Binder - Mapping class: com.tsystems.ecm.imaes.imadb.hibernate2.archive.ImsSpecTable -> IMS_SPEC_TABLE
DEBUG cfg.Binder - Mapped property: imsDocid -> IMS_DOCID, type: long
DEBUG cfg.Binder - Mapped property: imsField1 -> IMS_FIELD1, type: string
DEBUG cfg.Binder - Mapped property: version -> VERSION, type: integer
DEBUG cfg.Binder - Mapped property: comp_id -> IMS_DOCID, IMS_FIELD1, VERSION, type: com.tsystems.ecm.imaes.imadb.hibernate2.archive.ImsSpecTablePK
DEBUG cfg.Binder - Mapped property: imsSpec -> IMS_SPEC, type: string
DEBUG cfg.Binder - Mapped property: imsField2 -> IMS_FIELD2, type: string
DEBUG cfg.Binder - Mapped property: title -> TITLE, type: string
DEBUG cfg.Binder - Mapped property: validationtype -> VALIDATIONTYPE, type: integer
DEBUG cfg.Binder - Mapped property: checksum -> CHECKSUM, type: byte
DEBUG cfg.Binder - Mapped property: filesize -> FILESIZE, type: long
DEBUG cfg.Binder - Mapped property: valid -> VALID, type: integer
DEBUG cfg.Binder - Mapped property: ftname -> FTNAME, type: string
DEBUG cfg.Binder - Mapped property: archiveFileSet -> IMS_DOCID, VERSION, type: com.tsystems.ecm.imaes.imadb.hibernate2.archive.ImsTable
INFO cfg.Configuration - processing one-to-many association mappings
DEBUG cfg.Binder - Second pass for collection: com.tsystems.ecm.imaes.imadb.hibernate2.archive.ImsTable.archiveFiles
INFO cfg.Binder - Mapping collection: com.tsystems.ecm.imaes.imadb.hibernate2.archive.ImsTable.archiveFiles -> IMS_SPEC_TABLE
DEBUG cfg.Binder - Mapped collection key: IMS_DOCID, one-to-many: com.tsystems.ecm.imaes.imadb.hibernate2.archive.ImsSpecTable
INFO cfg.Configuration - processing one-to-one association property references
INFO cfg.Configuration - processing foreign key constraints
DEBUG cfg.Configuration - resolving reference to class: com.tsystems.ecm.imaes.imadb.hibernate2.archive.ImsTable
%%%% Error Creating SessionFactory %%%%
Exception in Ims Table
java.lang.NullPointerException
net.sf.hibernate.MappingException: collection foreign key mapping has wrong number of columns: com.tsystems.ecm.imaes.imadb.hibernate2.archive.ImsTable.archiveFiles type: com.tsystems.ecm.imaes.imadb.hibernate2.archive.ImsTablePK
at net.sf.hibernate.mapping.Collection.validate(Collection.java:248)
at net.sf.hibernate.cfg.Configuration.validate(Configuration.java:589)
at net.sf.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:744)
at helper.HibernateSession.currentSession(HibernateSession.java:41)
at com.tsystems.ecm.imaes.imadb.hibernate2.archive.ImsTableDAO.save(ImsTableDAO.java:28)
at test.ImsTableTest.testSaveDFolder(ImsTableTest.java:77)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at junit.framework.TestCase.runTest(TestCase.java:154)
at junit.framework.TestCase.runBare(TestCase.java:127)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:118)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:474)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:342)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:194)

-------------------------------------------------------------------------------------

Mapping Documents

1. ImsTable.hbm.xml

<hibernate-mapping>
<class
name="com.tsystems.ecm.imaes.imadb.hibernate2.archive.ImsTable"
table="IMS_TABLE"
dynamic-update="false"
dynamic-insert="false"
>

<composite-id
name="comp_id"
class="com.tsystems.ecm.imaes.imadb.hibernate2.archive.ImsTablePK"
>
<key-property name="imsId" type="java.lang.Long" column="IMS_ID"/>
<key-property name="version" type="java.lang.Integer" column="VERSION"/>
</composite-id>

<property
name="imsType"
type="java.lang.String"
update="true"
insert="true"
column="IMS_TYPE"
length="5"
/>

<property
name="imsAno"
type="java.lang.String"
update="true"
insert="true"
column="IMS_ANO"
length="1"
/>

<property
name="imsStart"
type="java.lang.Long"
update="true"
insert="true"
column="IMS_START"
length="10"
/>

<property
name="imsPages"
type="java.lang.Long"
update="true"
insert="true"
column="IMS_PAGES"
length="10"
/>

<property
name="imsEnhance"
type="java.lang.String"
update="true"
insert="true"
column="IMS_ENHANCE"
length="1"
/>

<property
name="imsMaster"
type="java.lang.String"
update="true"
insert="true"
column="IMS_MASTER"
length="10"
/>

<property
name="imsCasIdRef"
type="java.lang.String"
update="true"
insert="true"
column="IMS_CAS_ID_REF"
length="10"
/>

<property
name="imsAdr"
type="java.lang.String"
update="true"
insert="true"
column="IMS_ADR"
length="12"
/>

<property
name="imsAdrArchive"
type="java.lang.String"
update="true"
insert="true"
column="IMS_ADR_ARCHIVE"
length="12"
/>

<property
name="imsHeader"
type="java.lang.String"
update="true"
insert="true"
column="IMS_HEADER"
length="12"
/>

<set
name="archiveFiles"
lazy="true"
inverse="true"
cascade="none"
sort="unsorted"
>
<key
column="IMS_DOCID"
/>

<one-to-many
class="com.tsystems.ecm.imaes.imadb.hibernate2.archive.ImsSpecTable"
/>
</set>

<!--
To add non XDoclet property mappings, create a file named
hibernate-properties-ImsTable.xml
containing the additional properties and place it in your merge dir.
-->

</class>
</hibernate-mapping>

2. ImsSpecTable.hbm.xml

<hibernate-mapping>
<class
name="com.tsystems.ecm.imaes.imadb.hibernate2.archive.ImsSpecTable"
table="IMS_SPEC_TABLE"
dynamic-update="false"
dynamic-insert="false"
>

<composite-id
name="comp_id"
class="com.tsystems.ecm.imaes.imadb.hibernate2.archive.ImsSpecTablePK"
>
<key-property
name="imsDocid"
type="java.lang.Long"
column="IMS_DOCID"
/>

<key-property
name="imsField1"
type="java.lang.String"
column="IMS_FIELD1"
/>

<key-property
name="version"
type="java.lang.Integer"
column="VERSION"
/>

</composite-id>

<property
name="imsSpec"
type="java.lang.String"
update="true"
insert="true"
column="IMS_SPEC"
length="10"
/>

<property
name="imsField2"
type="java.lang.String"
update="true"
insert="true"
column="IMS_FIELD2"
length="254"
/>

<property
name="title"
type="java.lang.String"
update="true"
insert="true"
column="TITLE"
length="254"
/>

<property
name="validationtype"
type="java.lang.Integer"
update="true"
insert="true"
column="VALIDATIONTYPE"
length="4"
/>

<property
name="checksum"
type="byte"
update="true"
insert="true"
column="CHECKSUM"
length="20"
/>

<property
name="filesize"
type="java.lang.Long"
update="true"
insert="true"
column="FILESIZE"
length="12"
/>

<property
name="valid"
type="java.lang.Integer"
update="true"
insert="true"
column="VALID"
length="1"
/>

<property
name="ftname"
type="java.lang.String"
update="true"
insert="true"
column="FTNAME"
length="254"
/>

<many-to-one
name="archiveFileSet"
class="com.tsystems.ecm.imaes.imadb.hibernate2.archive.ImsTable"
cascade="none"
outer-join="auto"
update="false"
insert="false"
>
<column
name="IMS_DOCID"
/>
<column
name="VERSION"
/>
</many-to-one>

<!--
To add non XDoclet property mappings, create a file named
hibernate-properties-ImsSpecTable.xml
containing the additional properties and place it in your merge dir.
-->

</class>

</hibernate-mapping>

I hope I was able to explain my problem. Please let me know where am i going wrong.


Top
 Profile  
 
 Post subject: Re: Mapping Exception
PostPosted: Tue Aug 30, 2005 7:15 am 
Beginner
Beginner

Joined: Tue Jul 19, 2005 4:03 am
Posts: 34
Location: Aberdeen, UK
The issue could reside in how you have defined your SET in the map for the ImsTable. The ImsSpecTable has a 3 key composite key, so you have to define 2 keys in the set. You do this by using the the key element with nested column elements.

The map file would then look something like this:

Code:
<set name="archiveFiles" lazy="true" inverse="true" cascade="none" sort="unsorted">
    <key>
        <column name="IMS_DOCID"/>
        <column name="IMS_FIELD1"/>
    </key>
    <one-to-many
class="com.tsystems.ecm.imaes.imadb.hibernate2.archive.ImsSpecTable"/>
</set>


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 30, 2005 8:00 am 
Newbie

Joined: Tue Aug 30, 2005 5:56 am
Posts: 2
Hello Ardal,

Thanks for your posting. It worked!!! Thanks.

But could you please elaborate on your statement

"ImsSpecTable has a 3 key composite key, so you have to define 2 keys in the set."

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 30, 2005 8:17 am 
Beginner
Beginner

Joined: Tue Jul 19, 2005 4:03 am
Posts: 34
Location: Aberdeen, UK
I’ll try!

Your class had a composite key made up of three columns. To use the set element in Hibernate, you have to specify the two foreign key columns in you set and one-to-many element will define the last column in your composite key.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 08, 2005 9:47 am 
Beginner
Beginner

Joined: Tue Sep 06, 2005 5:16 pm
Posts: 24
Location: USA
Hi ardal,

Your suggestion helped me...I wanted to rate you ...But i don't know how to rate..

Thanks Again ardal


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 08, 2005 9:53 am 
Beginner
Beginner

Joined: Tue Jul 19, 2005 4:03 am
Posts: 34
Location: Aberdeen, UK
That’s ok!

Only the person that started the thread can rate!

Glad to be of help anyway:)


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