-->
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.  [ 2 posts ] 
Author Message
 Post subject: MappingException: id mapping has wrong number of columns
PostPosted: Tue Sep 07, 2004 10:35 pm 
Newbie

Joined: Tue Sep 07, 2004 12:00 am
Posts: 6
generated xml using middlegen and generated java classes using hbm2java....

schema consists of three classes, "Cat", "Toy" and "many-to-many" associative entity "CatHasToy"...

hbm2java created CatHasToyPK...

relevent info supplied below. any assistance appreciated ;)


Hibernate version:
2.1.6

Mapping documents:

Cat.hbm.xml:

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" >

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

http://boss.bekk.no/boss/middlegen/
http://www.hibernate.org/
-->

<class
name="cat.hibernate.Cat"
table="cat"
>

<id
name="oid"
type="java.lang.Object"
column="oid"
>
<generator class="assigned" />
</id>

<property
name="name"
type="java.lang.String"
column="name"
not-null="true"
length="20"
/>

<!-- Associations -->

<!-- bi-directional one-to-many association to CatHasToy -->
<set
name="catHasToys"
lazy="true"
inverse="true"
cascade="none"
>
<key>
<column name="cat_oid" />
</key>
<one-to-many
class="cat.hibernate.CatHasToy"
/>
</set>

</class>
</hibernate-mapping>

Toy.hbm.xml:

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" >

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

http://boss.bekk.no/boss/middlegen/
http://www.hibernate.org/
-->

<class
name="cat.hibernate.Toy"
table="toy"
>

<id
name="oid"
type="java.lang.Object"
column="oid"
>
<generator class="assigned" />
</id>

<property
name="name"
type="java.lang.String"
column="name"
not-null="true"
length="20"
/>

<!-- Associations -->

<!-- bi-directional one-to-many association to CatHasToy -->
<set
name="catHasToys"
lazy="true"
inverse="true"
cascade="none"
>
<key>
<column name="toy_oid" />
</key>
<one-to-many
class="cat.hibernate.CatHasToy"
/>
</set>

</class>
</hibernate-mapping>


CatHasToy.hbm.xml:

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" >

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

http://boss.bekk.no/boss/middlegen/
http://www.hibernate.org/
-->

<class
name="cat.hibernate.CatHasToy"
table="cat_has_toy"
>

<composite-id name="comp_id" class="cat.hibernate.CatHasToyPK">
<key-property
name="catOid"
column="cat_oid"
type="java.lang.Object"
length="10"
/>
<key-property
name="toyOid"
column="toy_oid"
type="java.lang.Object"
length="10"
/>
</composite-id>

<property
name="biteMarks"
type="java.lang.Object"
column="biteMarks"
length="10"
/>

<!-- Associations -->
<!-- derived association(s) for compound key -->
<!-- bi-directional many-to-one association to Toy -->
<many-to-one
name="toy"
class="cat.hibernate.Toy"
update="false"
insert="false"
>
<column name="toy_oid" />
</many-to-one>

<!-- bi-directional many-to-one association to Cat -->
<many-to-one
name="cat"
class="cat.hibernate.Cat"
update="false"
insert="false"
>
<column name="cat_oid" />
</many-to-one>

<!-- end of derived association(s) -->


</class>
</hibernate-mapping>

Code between sessionFactory.openSession() and session.close():

Session session = HibernateHelper.currentSession();

Transaction tx= session.beginTransaction();

Cat cat = new Cat();
cat.setName("Whiskers");

session.save(cat);
tx.commit();

HibernateHelper.closeSession();

Full stack trace of any exception that occurs:

net.sf.hibernate.MappingException: identifier mapping has wrong number of columns: cat.hibernate.Toy type: object
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)
at com.tony.hibernate.HibernateHelper.<clinit>(HibernateHelper.java:34)
at com.tony.hibernate.test.Test.main(Test.java:36)

Name and version of the database you are using:
mysql: 4.0.20a

Debug level Hibernate log excerpt:

22:16:34,207 INFO Environment:469 - Hibernate 2.1.6
22:16:34,217 INFO Environment:498 - hibernate.properties not found
22:16:34,227 INFO Environment:529 - using CGLIB reflection optimizer
22:16:34,227 INFO Configuration:895 - configuring from resource: /hibernate.cfg.xml
22:16:34,237 INFO Configuration:867 - Configuration resource: /hibernate.cfg.xml
22:16:34,387 DEBUG DTDEntityResolver:20 - trying to locate http://hibernate.sourceforge.net/hibern ... on-2.0.dtd in classpath under net/sf/hibernate/
22:16:34,387 DEBUG DTDEntityResolver:29 - found http://hibernate.sourceforge.net/hibern ... on-2.0.dtd in classpath
22:16:34,477 DEBUG Configuration:853 - hibernate.connection.driver_class=org.gjt.mm.mysql.Driver
22:16:34,477 DEBUG Configuration:853 - hibernate.connection.url=jdbc:mysql://localhost/cat
22:16:34,487 DEBUG Configuration:853 - hibernate.connection.username=root
22:16:34,487 DEBUG Configuration:853 - hibernate.connection.pool_size=5
22:16:34,487 DEBUG Configuration:853 - show_sql=true
22:16:34,487 DEBUG Configuration:853 - dialect=net.sf.hibernate.dialect.MySQLDialect
22:16:34,487 DEBUG Configuration:1012 - null<-org.dom4j.tree.DefaultAttribute@1172e08 [Attribute: name resource value "Cat.hbm.xml"]
22:16:34,487 INFO Configuration:331 - Mapping resource: Cat.hbm.xml
22:16:34,497 DEBUG DTDEntityResolver:20 - trying to locate http://hibernate.sourceforge.net/hibern ... ng-2.0.dtd in classpath under net/sf/hibernate/
22:16:34,507 DEBUG DTDEntityResolver:29 - found http://hibernate.sourceforge.net/hibern ... ng-2.0.dtd in classpath
22:16:34,698 INFO Binder:229 - Mapping class: cat.hibernate.Cat -> cat
22:16:34,798 DEBUG Binder:486 - Mapped property: oid -> oid, type: object
22:16:34,818 DEBUG Binder:486 - Mapped property: name -> name, type: string
22:16:34,848 DEBUG Binder:486 - Mapped property: catHasToys, type: java.util.Set
22:16:34,848 DEBUG Configuration:1012 - null<-org.dom4j.tree.DefaultAttribute@1e4457d [Attribute: name resource value "CatHasToy.hbm.xml"]
22:16:34,848 INFO Configuration:331 - Mapping resource: CatHasToy.hbm.xml
22:16:34,858 DEBUG DTDEntityResolver:20 - trying to locate http://hibernate.sourceforge.net/hibern ... ng-2.0.dtd in classpath under net/sf/hibernate/
22:16:34,858 DEBUG DTDEntityResolver:29 - found http://hibernate.sourceforge.net/hibern ... ng-2.0.dtd in classpath
22:16:34,928 INFO Binder:229 - Mapping class: cat.hibernate.CatHasToy -> cat_has_toy
22:16:34,928 DEBUG Binder:486 - Mapped property: catOid -> cat_oid, type: object
22:16:34,928 DEBUG Binder:486 - Mapped property: toyOid -> toy_oid, type: object
22:16:35,178 DEBUG Binder:486 - Mapped property: comp_id -> cat_oid, toy_oid, type: cat.hibernate.CatHasToyPK
22:16:35,178 DEBUG Binder:486 - Mapped property: biteMarks -> biteMarks, type: object
22:16:35,178 DEBUG Binder:486 - Mapped property: toy -> toy_oid, type: cat.hibernate.Toy
22:16:35,178 DEBUG Binder:486 - Mapped property: cat -> cat_oid, type: cat.hibernate.Cat
22:16:35,198 DEBUG Configuration:1012 - null<-org.dom4j.tree.DefaultAttribute@82701e [Attribute: name resource value "Toy.hbm.xml"]
22:16:35,198 INFO Configuration:331 - Mapping resource: Toy.hbm.xml
22:16:35,198 DEBUG DTDEntityResolver:20 - trying to locate http://hibernate.sourceforge.net/hibern ... ng-2.0.dtd in classpath under net/sf/hibernate/
22:16:35,208 DEBUG DTDEntityResolver:29 - found http://hibernate.sourceforge.net/hibern ... ng-2.0.dtd in classpath
22:16:35,248 INFO Binder:229 - Mapping class: cat.hibernate.Toy -> toy
22:16:35,248 DEBUG Binder:486 - Mapped property: oid -> oid, type: object
22:16:35,248 DEBUG Binder:486 - Mapped property: name -> name, type: string
22:16:35,248 DEBUG Binder:486 - Mapped property: catHasToys, type: java.util.Set
22:16:35,248 INFO Configuration:1053 - Configured SessionFactory: null
22:16:35,248 DEBUG Configuration:1054 - properties: {java.runtime.name=Java(TM) 2 Runtime Environment, Standard Edition, sun.boot.library.path=C:\Program Files\Java\jdk1.5.0\jre\bin, java.vm.version=1.5.0-beta2-b51, hibernate.connection.username=root, java.vm.vendor=Sun Microsystems Inc., java.vendor.url=http://java.sun.com/, path.separator=;, java.vm.name=Java HotSpot(TM) Client VM, file.encoding.pkg=sun.io, user.country=US, sun.os.patch.level=Service Pack 1, java.vm.specification.name=Java Virtual Machine Specification, user.dir=C:\tony\eclipse\hibernateTest2, java.runtime.version=1.5.0-beta2-b51, java.awt.graphicsenv=sun.awt.Win32GraphicsEnvironment, java.endorsed.dirs=C:\Program Files\Java\jdk1.5.0\jre\lib\endorsed, os.arch=x86, java.io.tmpdir=C:\DOCUME~1\a716948\LOCALS~1\Temp\, line.separator=
, java.vm.specification.vendor=Sun Microsystems Inc., user.variant=, os.name=Windows XP, sun.jnu.encoding=Cp1252, java.library.path=C:\Program Files\Java\jdk1.5.0\bin;.;C:\WINNT\System32;C:\WINNT;C:\Program Files\Java\jdk1.5.0\bin;c:\cygwin\bin;C:\IBM\IMNNQ;C:\Program Files\Hummingbird\Connectivity\7.10\Accessories\;C:\DB2_SQLLIB\BIN;C:\DB2_SQLLIB\FUNCTION;C:\DB2_SQLLIB\SAMPLES\REPL;C:\DB2_SQLLIB\HELP;C:\Program Files\IBM\WebSphere MQ\bin;C:\WINNT\SYSTEM32;C:\WINNT;C:\WINNT\SYSTEM32\WBEM;C:\RUMBA\SYSTEM;C:\Program Files\Winzip;C:\Rumba\Windows;C:\Program Files\Rational\common;C:\Program Files\Rational\ClearCase\bin;C:\Program Files\cvsnt;C:\Program Files\Apache Software Foundation\Maven 1.0\bin;c:\java\apache-ant-1.6.2\bin, java.specification.name=Java Platform API Specification, java.class.version=49.0, hibernate.connection.pool_size=5, sun.management.compiler=HotSpot Client Compiler, java.util.prefs.PreferencesFactory=java.util.prefs.WindowsPreferencesFactory, os.version=5.1, user.home=C:\Documents and Settings\a716948, user.timezone=America/New_York, java.awt.printerjob=sun.awt.windows.WPrinterJob, file.encoding=Cp1252, java.specification.version=1.5, hibernate.connection.driver_class=org.gjt.mm.mysql.Driver, show_sql=true, user.name=A716948, java.class.path=C:\tony\eclipse\hibernateTest2\bin;C:\hibernate\hibernate-2.1\lib\commons-lang-1.0.1.jar;C:\hibernate\hibernate-2.1\hibernate2.jar;C:\hibernate\hibernate-2.1\lib\commons-logging-1.0.4.jar;C:\java\dom4j-1.4\dom4j.jar;C:\hibernate\hibernate-2.1\lib\commons-collections-2.1.1.jar;C:\hibernate\hibernate-2.1\lib\odmg-3.0.jar;C:\hibernate\hibernate-2.1\lib\cglib-full-2.0.2.jar;C:\tony\eclipse\hibernateTest2\config\cat\hibernate;C:\hibernate\hibernate-2.1\lib\log4j-1.2.8.jar, hibernate.show_sql=true, java.vm.specification.version=1.0, java.home=C:\Program Files\Java\jdk1.5.0\jre, sun.arch.data.model=32, hibernate.dialect=net.sf.hibernate.dialect.MySQLDialect, hibernate.connection.url=jdbc:mysql://localhost/cat, user.language=en, java.specification.vendor=Sun Microsystems Inc., awt.toolkit=sun.awt.windows.WToolkit, hibernate.cglib.use_reflection_optimizer=true, java.vm.info=mixed mode, sharing, java.version=1.5.0-beta2, java.ext.dirs=C:\Program Files\Java\jdk1.5.0\jre\lib\ext, sun.boot.class.path=C:\Program Files\Java\jdk1.5.0\jre\lib\rt.jar;C:\Program Files\Java\jdk1.5.0\jre\lib\i18n.jar;C:\Program Files\Java\jdk1.5.0\jre\lib\sunrsasign.jar;C:\Program Files\Java\jdk1.5.0\jre\lib\jsse.jar;C:\Program Files\Java\jdk1.5.0\jre\lib\jce.jar;C:\Program Files\Java\jdk1.5.0\jre\lib\charsets.jar;C:\Program Files\Java\jdk1.5.0\jre\classes, java.vendor=Sun Microsystems Inc., file.separator=\, java.vendor.url.bug=http://java.sun.com/cgi-bin/bugreport.cgi, sun.io.unicode.encoding=UnicodeLittle, sun.cpu.endian=little, sun.desktop=windows, dialect=net.sf.hibernate.dialect.MySQLDialect, sun.cpu.isalist=}
22:16:35,248 INFO Configuration:627 - processing one-to-many association mappings
22:16:35,248 DEBUG Binder:1353 - Second pass for collection: cat.hibernate.Cat.catHasToys
22:16:35,248 INFO Binder:1181 - Mapping collection: cat.hibernate.Cat.catHasToys -> cat_has_toy
22:16:35,248 DEBUG Binder:1368 - Mapped collection key: cat_oid, one-to-many: cat.hibernate.CatHasToy
22:16:35,248 DEBUG Binder:1353 - Second pass for collection: cat.hibernate.Toy.catHasToys
22:16:35,258 INFO Binder:1181 - Mapping collection: cat.hibernate.Toy.catHasToys -> cat_has_toy
22:16:35,258 DEBUG Binder:1368 - Mapped collection key: toy_oid, one-to-many: cat.hibernate.CatHasToy
22:16:35,258 INFO Configuration:636 - processing one-to-one association property references
22:16:35,258 INFO Configuration:661 - processing foreign key constraints
22:16:35,258 DEBUG Configuration:678 - resolving reference to class: cat.hibernate.Toy
22:16:35,258 DEBUG Configuration:678 - resolving reference to class: cat.hibernate.Cat
22:16:35,268 ERROR HibernateHelper:38 - Initial SessionFactory creation failed.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 15, 2004 11:22 pm 
Newbie

Joined: Tue Sep 07, 2004 12:00 am
Posts: 6
in case anyone is interested, turns out that middlegen generated hbm files such that items specified as integers in database are specified as java.lang.Object.

i read in another posting that elements specified as java.lang.Object require an additional (string) column specifying the classname?

i'm not positive that this is the case, but modifying the hbm files converting java.lang.Object to int (in the case of my sample), and then invoking hbm2java resulted in the desired effect.

does anyone know if there is some way to tweak middlegen to use more appropriate types instead of java.lang.Object?

or is there some other tweakage that i'm missing, perhaps in hbm2java?

thanks!


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