-->
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.  [ 3 posts ] 
Author Message
 Post subject: map relationship
PostPosted: Mon Feb 07, 2005 3:39 pm 
Newbie

Joined: Mon Feb 07, 2005 3:17 pm
Posts: 4
I'm trying to use a map relationship that has a database setup that is a bit different than all examples that I have seen.

Parent Table SBT_BGT_STRGRP_HRS (see mapping document for details)
has a composite id of two ints. One of these ints is a foreign key to the child table.

Child Table SBT_OPER_HRS_NM
key = foreign key from parent table (I am attempting to use this as the key to my map)
child = OPER_HRS_NM (I am attempting to use this as the value in my map)


The error that I am getting (see below) implies that my key must use both parts of the primary key, however, only one part of the primary key is the foreign key into my child table.

From my hibernate experience, I'm starting to get the idea that composite id's are not reccommended.
Any ideas?


Hibernate version:2.0

Mapping documents:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 2.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping package="com.kohls.sb.sb.common.entity">
<class name="DayType" table="SBT_BGT_STRGRP_HRS">
<composite-id>
<key-property name="groupId" column="STR_BGT_GRP_ID" type="java.lang.Integer"/>
<key-property name="hoursId" column="OPER_HRS_ID" type="java.lang.Integer"/>
</composite-id>
<property name="operatingHoursCode" column="OPER_HRS_CDE" type="java.lang.Integer" not-null="true"/>
<map name="dayNames" table="SBT_OPER_HRS_NM">
<key column="OPER_HRS_ID"/>
<index column="OPER_HRS_ID" type="java.lang.Integer"/>
<element column="OPER_HRS_NM" type="string"/>
</map>
</class>
</hibernate-mapping>

Full stack trace of any exception that occurs:
[2005-02-07 13:00:11,424] [main] ERROR - Failed to initalize: class com.kohls.sb.sb.server.dao.SBPersistFactory configuration exception Foreign key (SBT_OPER_HRS_NM [OPER_HRS_ID])) must have same number of columns as the referenced primary key (SBT_BGT_STRGRP_HRS [STR_BGT_GRP_ID,OPER_HRS_ID]) -com.kohls.sb.sb.server.dao.SBPersistFactory
net.sf.hibernate.MappingException: Foreign key (SBT_OPER_HRS_NM [OPER_HRS_ID])) must have same number of columns as the referenced primary key (SBT_BGT_STRGRP_HRS [STR_BGT_GRP_ID,OPER_HRS_ID])
at net.sf.hibernate.mapping.ForeignKey.setReferencedTable(ForeignKey.java:60)
at net.sf.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:667)
at net.sf.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:761)
at com.kohls.sb.sb.server.dao.SBPersistFactory.init(SBPersistFactory.java:34)
at com.kohls.sb.sb.server.dao.SBPersistFactory.getInstance(SBPersistFactory.java:70)
at com.kohls.sb.sb.server.dao.BaseDao.findAll(BaseDao.java:39)
at com.kohls.sb.sb.server.facade.BudgetFacadeBean.findAll(BudgetFacadeBean.java:214)
at com.kohls.sb.sb.server.facade.BudgetFacadeBean_vg38e_EOImpl.findAll(BudgetFacadeBean_vg38e_EOImpl.java:584)
at com.kohls.sb.sb.server.application.SBServerCache.initialize(SBServerCache.java:63)
at com.kohls.sb.sb.server.application.SBServerCache.<init>(SBServerCache.java:43)
at com.kohls.sb.sb.server.application.SBServerCache.<clinit>(SBServerCache.java:271)
at com.kohls.sb.sb.server.facade.BudgetFacadeBean.ejbCreate(BudgetFacadeBean.java:78)
at com.kohls.sb.sb.server.facade.BudgetFacadeBean_vg38e_Impl.ejbCreate(BudgetFacadeBean_vg38e_Impl.java:135)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at weblogic.ejb20.pool.StatelessSessionPool.createBean(StatelessSessionPool.java:172)
at weblogic.ejb20.pool.Pool.createInitialBeans(Pool.java:254)
at weblogic.ejb20.manager.StatelessManager.initializePool(StatelessManager.java:376)
at weblogic.ejb20.deployer.EJBDeployer.initializePools(EJBDeployer.java:1530)
at weblogic.ejb20.deployer.EJBDeployer.start(EJBDeployer.java:1397)
at weblogic.ejb20.deployer.EJBModule.start(EJBModule.java:668)
at weblogic.j2ee.J2EEApplicationContainer.start(J2EEApplicationContainer.java:2022)
at weblogic.j2ee.J2EEApplicationContainer.activate(J2EEApplicationContainer.java:2063)
at weblogic.j2ee.J2EEApplicationContainer.activate(J2EEApplicationContainer.java:2010)
at weblogic.management.deploy.slave.SlaveDeployer$Application.setActivation(SlaveDeployer.java:3108)
at weblogic.management.deploy.slave.SlaveDeployer.setActivationStateForAllApplications(SlaveDeployer.java:1656)
at weblogic.management.deploy.slave.SlaveDeployer.resume(SlaveDeployer.java:372)
at weblogic.management.deploy.DeploymentManagerServerLifeCycleImpl.resume(DeploymentManagerServerLifeCycleImpl.java:229)
at weblogic.t3.srvr.SubsystemManager.resume(SubsystemManager.java:131)
at weblogic.t3.srvr.T3Srvr.resume(T3Srvr.java:964)
at weblogic.t3.srvr.T3Srvr.run(T3Srvr.java:359)
at weblogic.Server.main(Server.java:32)


Name and version of the database you are using:
DB2


Top
 Profile  
 
 Post subject: foreignKEY
PostPosted: Mon Feb 07, 2005 4:17 pm 
Newbie

Joined: Tue Dec 14, 2004 2:57 pm
Posts: 12
If I'm understanding correctly, your trying to do a many-to-may mapping, where all DayType's with a common hoursId point to the same set of HRS_NM (you didn't include the mapping for the child).

In any case, you must realize that a Foreign Key is a KEY that is in another table. ie It must refer to a whole key, such as a primary key.

--Ryan


Top
 Profile  
 
 Post subject: more info
PostPosted: Tue Feb 08, 2005 12:28 pm 
Newbie

Joined: Mon Feb 07, 2005 3:17 pm
Posts: 4
Child DayName mapping =
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 2.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping package="com.kohls.sb.sb.common.entity">
<class name="DayTypeName" table="SBT_OPER_HRS_NM">
<id name="code" column="OPER_HRS_ID" type="java.lang.Integer">
<generator class="identity"/>
</id>
<property name="dayName" column="OPER_HRS_NM" type="com.kohls.sb.sb.server.util.TrimmedString" length="30" not-null="true"/>
</class>
</hibernate-mapping>


Perhaps a light bulb just went off. I really only have a 1-1 mapping. I just want to get the value of a code from my child table into my parent object.

This sounds easy. Any ideas on the best approach?


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