I have a one-to-many association and the key is a composite of 2 fields in the DB and the PO objects. I get the error "Foreign key (SkillsetSiteAssociationAdmin [skillsetName])) must have same number of columns as the referenced primary key (SkillsetAdmin [skill ] setName,configID])" and am not sure what the syntax is to support this in the asscociation or if it is even possible.
Can someone please give me some input on these more complicated associations or give me a reference. I have found several other people struggling with this but have not seen a solution as yet.
Thanks, Alex.
Hibernate version:hibernate2.1.6.jar
Mapping documents:
/**
* @hibernate.set
* role="skillsetSiteAssociationsAdmin"
* cascade="all"
* lazy="false"
* @hibernate.collection-key
* column="skillsetName"
* column="configID"
/*** Not sure of the syntax to add 2nd column***/
* @hibernate.collection-one-to-many
* class="com.telus.ccs.adminRouting.model.po.SkillsetSiteAssociationAdmin"
* not-null="true"
* unique="true"
*/
public Set getSkillsetSiteAssociationAdmin() {
return this.skillsetSiteAssociations;
}
Table Create:
***********
create table SkillsetAdmin (
configID number not null,
skillsetName varchar2(40) not null,
skillsetType varchar2(20) not null,
primary key (skillsetName, configID)
);
Table Constraint:
***************
alter table SkillsetSiteAssociationAdmin add constraint FKSiteREFSkillset foreign key (skillsetName, configID) references SkillsetAd
min;
Code between sessionFactory.openSession() and session.close():
Full stack trace of any exception that occurs:
##PEM Mapping resource: com/telus/ccs/adminRouting/model/po/SkillsetAdmin.hbm.xml
##PEM trying to locate
http://hibernate.sourceforge.net/hibern ... ng-2.0.dtd in classpath under net/sf/hibernate/
##PEM found
http://hibernate.sourceforge.net/hibern ... ng-2.0.dtd in classpath
[Loaded com.telus.ccs.adminRouting.model.po.SkillsetAdmin]
##PEM Mapping class: com.telus.ccs.adminRouting.model.po.SkillsetAdmin -> SkillsetAdmin
[Loaded com.telus.ccs.adminRouting.model.po.SkillsetAdminKey]
##PEM Mapped property: skillsetName -> skillsetName, type: string
##PEM Mapped property: configID -> configID, type: integer
[Loaded com.telus.ccs.adminRouting.model.po.SkillsetAdminKey$$FastClassByCGLIB$$bf282571]
[Loaded com.telus.ccs.adminRouting.model.po.SkillsetAdminKey$$BulkBeanByCGLIB$$2c9c95c7]
##PEM Mapped property: id -> skillsetName, configID, type: com.telus.ccs.adminRouting.model.po.SkillsetAdminKey
##PEM Mapped property: skillsetType -> skillsetType, type: string
[Loaded com.telus.ccs.adminRouting.model.po.SkillsetSiteAssociationAdmin]
##PEM Mapped property: skillsetSiteAssociationAdmin, type: java.util.Set
#PEM null<-org.dom4j.tree.DefaultAttribute@57c2bd [Attribute: name resource value "com/telus/ccs/adminRouting/model/po/SkillsetSiteAssociationAdmin.hbm.xml"]
##PEM Mapping resource: com/telus/ccs/adminRouting/model/po/SkillsetSiteAssociationAdmin.hbm.xml
##PEM trying to locate
http://hibernate.sourceforge.net/hibern ... ng-2.0.dtd in classpath under net/sf/hibernate/
##PEM found
http://hibernate.sourceforge.net/hibern ... ng-2.0.dtd in classpath
##PEM Mapping class: com.telus.ccs.adminRouting.model.po.SkillsetSiteAssociationAdmin -> SkillsetSiteAssociationAdmin
##PEM Mapped property: recordID -> recordID, type: integer
##PEM Mapped property: skillsetName -> skillsetName, type: string
##PEM Mapped property: siteName -> siteName, type: string
##PEM Mapped property: percentage -> percentage, type: integer
##PEM Mapped property: phoneNumber -> phoneNumber, type: string
##PEM Mapped property: configID -> configID, type: integer
##PEM processing one-to-many association mappings
##PEM Second pass for collection: com.telus.ccs.adminRouting.model.po.Skillset.skillsetSiteAssociations
##PEM Mapping collection: com.telus.ccs.adminRouting.model.po.Skillset.skillsetSiteAssociations -> SkillsetSiteAssociation
##PEM Mapped collection key: skillsetName, one-to-many: com.telus.ccs.adminRouting.model.po.SkillsetSiteAssociation
##PEM Second pass for collection: com.telus.ccs.adminRouting.model.po.SkillsetAdmin.skillsetSiteAssociationAdmin
##PEM Mapping collection: com.telus.ccs.adminRouting.model.po.SkillsetAdmin.skillsetSiteAssociationAdmin -> SkillsetSiteAssociationAdmin
##PEM Mapped collection key: skillsetName, one-to-many: com.telus.ccs.adminRouting.model.po.SkillsetSiteAssociationAdmin
##PEM processing one-to-one association property references
##PEM processing foreign key constraints
[Loaded java.util.HashMap$2 from /bea/jdk131_06/jre/lib/rt.jar]
##PEM resolving reference to class: com.telus.ccs.adminRouting.model.po.SkillsetAdmin
[Loaded net.sf.hibernate.exception.NestableDelegate]
[Loaded com.telus.ccs.common.storage.TLStorage]
[Loaded com.telus.ccs.common.storage.TLStorage$TL]
[Loaded org.apache.commons.lang.time.DateFormatUtils]
[Loaded org.apache.commons.lang.time.FastDateFormat]
[Loaded org.apache.commons.lang.time.FastDateFormat$Rule]
[Loaded org.apache.commons.lang.time.FastDateFormat$NumberRule]
[Loaded org.apache.commons.lang.time.FastDateFormat$TextField]
[Loaded org.apache.commons.lang.time.FastDateFormat$UnpaddedNumberField]
[Loaded org.apache.commons.lang.time.FastDateFormat$Pair]
[Loaded org.apache.commons.lang.time.FastDateFormat$CharacterLiteral]
[Loaded org.apache.commons.lang.time.FastDateFormat$TwoDigitMonthField]
[Loaded org.apache.commons.lang.time.FastDateFormat$TwoDigitNumberField]
[Loaded org.apache.commons.lang.time.FastDateFormat$TimeZoneNumberRule]
[Loaded java.text.resources.LocaleElements_en_US from /bea/jdk131_06/jre/lib/rt.jar]
[Loaded java.util.ResourceBundle$1 from /bea/jdk131_06/jre/lib/rt.jar]
[Loaded org.apache.commons.lang.time.FastDateFormat$StringLiteral]
##PEM 2005.11.30-13:35:09 ivrapp02.ent.agt.ab.ca UNTITLED FATAL com.telus.ccs.util.DAO [ -1 Failed to obtain hibernate session:
net.sf.hibernate.MappingException Foreign key (SkillsetSiteAssociationAdmin [skillsetName])) must have same number of columns as the referenced primary key (SkillsetAdmin [skill ] setName,configID])
[Loaded java.lang.ExceptionInInitializerError from /bea/jdk131_06/jre/lib/rt.jar]
Exception in thread "main" java.lang.ExceptionInInitializerError: com.telus.ccs.base.DataAccessException: null; nested exception is net.sf.hibernate.MappingException: Foreign key (SkillsetSiteAssociationAdmin [skillsetName])) must have same number of columns as the referenced primary key (SkillsetAdmin [skillsetName,configID])
at com.telus.ccs.util.SessionFactoryUtil.<clinit>(SessionFactoryUtil.java:29)
at com.telus.ccs.util.DAO.read(DAO.java:95)
at test.ConfigDAOtest.main(ConfigDAOtest.java:36)[Loaded java.lang.Shutdown$Lock from /bea/jdk131_06/jre/lib/rt.jar]
Name and version of the database you are using:
Oracle 9.0
The generated SQL (show_sql=true):
Debug level Hibernate log excerpt: