-->
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: configuration error with <key-many-to-one> in composit
PostPosted: Fri Aug 20, 2004 2:03 pm 
Newbie

Joined: Fri Aug 20, 2004 1:13 pm
Posts: 10
Hibernate version:2.1.6 on jdk 1.4.2_05

I am very much a newbie and am working with a complex set of mappings that I generated with Middelgen and hbm2java. After generating all the xml mappings and .java files (which compile ok). I attempt to build a sesssionFactory and get an exception in:

buildSessionFactory()
Configuration c = new Configuration();
File file = new File("C:/_di/hibernatetest/src/com/drillinginfo/pennwell/hibernate/mapping");
c.addDirectory(file);
sessionFactory = c.buildSessionFactory(); //throws exception

Full stack trace of any exception that occurs:
Caused by: net.sf.hibernate.MappingException: identifier mapping has wrong number of columns: com.drillinginfo.pennwell.hibernate.WellboreTubingNarrative type: com.drillinginfo.pennwell.hibernate.WellboreTubingNarrativePK
at net.sf.hibernate.mapping.RootClass.validate(RootClass.java:171)
at net.sf.hibernate.cfg.Configuration.validate(Configuration.java:619)
at net.sf.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:785)



I know that if I cut out the <key-many-to-one> in the composite-id, I do not have an error.

I tried stepping thru the hibernate code and it appears for whatever reason, the RootClass, in this case a WellboreTubingNarrative, is loaded with a Identifier (a WellboreTubingNarrativePK) that has 0 columns. Since the mapping for the WellboreTubingNarrativePK has 4 columns, the Component.isValid(Mapping) throws the exception. I cant figure out why the RootClass is not properly initialized.

Mapping documents:/b]

-------------------------------------------------------------------------
<hibernate-mapping>
<!--
Created by the Middlegen Hibernate plugin

http://boss.bekk.no/boss/middlegen/
http://hibernate.sourceforge.net/
-->

<class
name="com.drillinginfo.pennwell.hibernate.WellboreTubingNarrative"
table="WELLBORE_TUBING_NARRATIVE"
>

<composite-id name="comp_id" class="com.drillinginfo.pennwell.hibernate.WellboreTubingNarrativePK">
<key-property
name="dataSourceCode"
column="DATA_SOURCE_CODE"
type="java.lang.String"
length="32"
/>
<key-property
name="sequenceNumber"
column="SEQUENCE_NUMBER"
type="java.lang.Integer"
length="10"
/>
<key-property
name="subSequenceNumber"
column="SUB_SEQUENCE_NUMBER"
type="java.lang.Integer"
length="10"
/>
<!-- bi-directional many-to-one association to Wellbore -->
<key-many-to-one
name="wellbore"
class="com.drillinginfo.pennwell.hibernate.Wellbore"
>
<column name="SYSTEM_WELL_ID_NUMBER" />
<column name="WELL_COMPLETION_NUMBER" />
</key-many-to-one>
</composite-id>

<property
name="uwiDataSource"
type="java.lang.String"
column="UWI_DATA_SOURCE"
length="20"
/>
<property
name="narrative"
type="java.lang.String"
column="NARRATIVE"
length="128"
/>
<property
name="recordLoadDate"
type="java.sql.Timestamp"
column="RECORD_LOAD_DATE"
length="23"
/>
<property
name="recordModificationDate"
type="java.sql.Timestamp"
column="RECORD_MODIFICATION_DATE"
length="23"
/>
<property
name="recordModificationBy"
type="java.lang.String"
column="RECORD_MODIFICATION_BY"
length="32"
/>

<!-- associations -->

</class>
</hibernate-mapping>
-------------------------------------------------------------------------





[b]Name and version of the database you are using:ms sql2k


Debug level Hibernate log excerpt:

_________________
-alan


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 20, 2004 2:08 pm 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
1-what happens if you cut
Code:
<key-many-to-one
name="wellbore"
class="com.drillinginfo.pennwell.hibernate.Wellbore"
>
<column name="SYSTEM_WELL_ID_NUMBER" />
<column name="WELL_COMPLETION_NUMBER" />
</key-many-to-one>
?

2- Wellbore have also a composite id define on 2 fields?

_________________
Anthony,
Get value thanks to your skills: http://www.redhat.com/certification


Top
 Profile  
 
 Post subject: configuration error with <key-many-to-one> in composit
PostPosted: Fri Aug 20, 2004 8:01 pm 
Newbie

Joined: Fri Aug 20, 2004 1:13 pm
Posts: 10
If I cut out the <key-many-to-one>, i didnt have the problem. I have traced out the problem and have a fix, although Im not altogether sure why it works. Apparently, Middelgen mapped SQLServer columns of type uniqueidentifier to a java.lang.Object. Changing the mapping to a String seems to fix the problem. I didnt fully diagnose the problem but got far enough to realize that hibernate was for some reason thinking that an Identity of type Object had 2 columns (I dont understand either).

Anyway, changing the ID to a String in the xml files and associated .java files fixed the problem.

Thanks, alan

_________________
-alan


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.