-->
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: Middlegen to Hibernate Many-to-Many mapping
PostPosted: Fri Jul 02, 2004 6:32 pm 
Newbie

Joined: Tue Jun 29, 2004 6:21 pm
Posts: 2
I seem to be having a problem with a many-to-many mapping using Middlegen to create my Hibernate POJO classes. I am not sure of how to correct the problem with the the last MappingException described below. I am only trying to initialize a Configuation at this point.

The tables I am investigating have the following structure:

Route:
ID (PK)
DocumentID
Name

Location:
ID (PK)
DocumentID

EntityInstanceAssociation:
EntityInstanceID (PK)
LocationID
RouteID

My particulars:

Hibernate 2.1.4

Middlegen mappings:

<table name="Location" singular="location" plural="locations"/>
<table name="Route" singular="route" plural="routes"/>
<table name="InstanceAssociation" singular="instanceAssociation" plural="instanceAssociations"/>

...
...
<many2many>
<tablea name="Location"/>
<jointable name="InstanceAssociation" generate="true"/>
<tableb name="Route"/>
</many2many>
...
...

Java Code:

Configuration cfg = new Configuration();

try{
...
cfg.addClass(com.swgas.pocket.Location.class);
cfg.addClass(com.swgas.pocket.Route.class);
cfg.addClass(com.swgas.pocket.InstanceAssociation.class);
...
}
catch(MappingException e) {
e.printStackTrace();
}

Stack Trace (abbreviated):

(cfg.Environment 432 ) Hibernate 2.1 rc1
(cfg.Environment 466 ) loaded properties from resource
...
hibernate.dialect=net.sf.hibernate.dialect.SQLServerDialect, hibernate.connection.url=jdbc:jtds:sqlserver://XYZ/Test;user=... hibernate.connection.driver_class=net.sourceforge.jtds.jdbc.Driver}
(cfg.Environment 481 ) using CGLIB reflection optimizer
(cfg.Configuration 305 ) Mapping resource: com/swgas/pocket/Location.hbm.xml
(cfg.Binder 196 ) Mapping class: com.swgas.pocket.Location -> Location
(cfg.Binder 502 ) Mapping collection: com.swgas.pocket.Location.routes -> InstanceAssociation
(cfg.Configuration 305 ) Mapping resource: com/swgas/pocket/Route.hbm.xml
(cfg.Binder 196 ) Mapping class: com.swgas.pocket.Route -> Route
(cfg.Binder 502 ) Mapping collection: com.swgas.pocket.Route.locations -> InstanceAssociation
...
(cfg.Configuration 574 ) processing one-to-one association property references
(cfg.Configuration 599 ) processing foreign key constraints
net.sf.hibernate.MappingException: Foreign key (InstanceAssociation [RouteId])) must have same number of columns as the reference primary key (Route [LineId,DocumentId])
at net.sf.hibernate.mapping.ForeignKey.setReferencedTable(ForeignKey.java:60)
at net.sf.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:619)
at net.sf.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:713)
at HibernateTest.main(Unknown Source)
Exception in thread "main"

Data Base: SQL Server 2000

Debug leve: Default


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 02, 2004 10:04 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
Need to show the mappings for the tables in question.


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.