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
|