-->
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.  [ 5 posts ] 
Author Message
 Post subject: wrong number of columns - middlegen generated mappings
PostPosted: Wed Jun 15, 2005 7:35 pm 
Beginner
Beginner

Joined: Wed Jun 15, 2005 7:14 pm
Posts: 28
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version: 2.1.7

Using Oracle 10g

I'm trying to use middlegen to create mappings from our database schema. I'm using middlegen 2.0 since 2.1 doesn't work with our Oracle 10g database - it keeps complaining about a bad schema - the one we list is in the list that it gives as possible schemas...go figure.
Anyway, I have a table that has three columns in its primary key. Two of those columns come from another table (a foreign key). Middlegen creates a primary key portion or component-like structure for the primary key with those three columns. However when the hbm2java runs, it creates a constructor that only takes two parameters. One is the data field specific to my table. The other parameter is an object where the foreign keyed fields come from. It reports that there is a wrong number of columns - a mapping exception when trying to load the mappings from the hibernate.cfg.xml file. Any help would be greatly appreciated!

Stack trace:
Exception in thread "main" net.sf.hibernate.MappingException: identifier mapping has wrong number of columns: com.mostlyharmless.travel.hibernate.TlAirVendorPref type: com.mostlyharmless.travel.hibernate.TlAirVendorPrefPK
at net.sf.hibernate.mapping.RootClass.validate(RootClass.java:171)
at net.sf.hibernate.cfg.Configuration.validate(Configuration.java:633)
at net.sf.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:799)
at com.mostlyharmless.travel.hibernate.util.TravelUtil.getSessionFactory(Unknown Source)
at com.mostlyharmless.travel.hibernate.util.TravelUtil.getSession(Unknown Source)
at com.mostlyharmless.travel.hibernate.HQL_MyAccount.getFees(HQL_MyAccount.java:33)
at com.mostlyharmless.travel.hibernate.HQL_MyAccount.main(HQL_MyAccount.java:75)

Composite-id mapping generated by middlegen:
<composite-id name="comp_id" class="com.mostlyharmless.travel.hibernate.TlAirVendorPrefPK">
<key-property
name="sequenceNumber"
column="SEQUENCE_NUMBER"
type="java.math.BigDecimal"
length="22"
/>
<!-- bi-directional many-to-one association to TlFlightPref -->
<key-many-to-one
name="tlFlightPref"
class="com.mostlyharmless.travel.hibernate.TlFlightPref"
>
<column name="CUSTOMER_ID" />
<column name="TRAVELER_ID" />
</key-many-to-one>
</composite-id>


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 15, 2005 8:11 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
The key-many-to-one property for composite keys is OK sometimes but in general you should not use them. In the case of Middlegen's generation of then there are cases that it will get the order incorrect. Middlgen can generate the composite key in both modes. Try the plain mode as it is more likely to work correctly.

As far as Middlegen 2.1 issues (with Oracle) there are some synom issues. I have not addressed them as yet. I can see the opportunity to catchup on a few things very coming up now that I just about to finsihed a project for a client.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 16, 2005 12:57 am 
Beginner
Beginner

Joined: Wed Jun 15, 2005 7:14 pm
Posts: 28
I'm sorry, I can't find documentation on plain mode composite key creation with the middlegen tool. How do I set that parameter when I start middlegen?


Top
 Profile  
 
 Post subject: Answer found in Middlegen 2.1
PostPosted: Thu Jun 16, 2005 12:26 pm 
Beginner
Beginner

Joined: Wed Jun 15, 2005 7:14 pm
Posts: 28
I had been using Middlegen 2.0 because it hadn't been working with Oracle 10g. Then I couldn't find what you were talking about with the plain compoundkey. So I tried 2.1 again with the connection string that was working with 2.0. For some reason that works now - I wonder if it was a problem with our database that was fixed between the first time I tried it and now...
In any case I found the plain compound key property of tables in the 2.1 gui. I generated with 2.1 and it looks like that particular problem has been fixed. Now on to new bugs!!! :)
Thanks again!


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jun 18, 2005 12:33 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
Cool (and no problem).


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