-->
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: Is there a way to use one column of a composite to do mappin
PostPosted: Wed Oct 15, 2008 4:40 pm 
Newbie

Joined: Mon Oct 06, 2008 12:18 pm
Posts: 2
I'm having problems wrapping my head around this to come with a suitable solution. I inherited this database that has a couple of tables that need to be mapped together. I discovered that composite keys must have the same number of columns (through a stack track seen below). Short question: Is this possible to match on a single column of a composite key? Long question: Could somebody point me to some code that could give me an example of this?

TIA,
Tino

PS: If you need anything else, please ask

Hibernate version: 3.2.5

Mapping documents:
Fullname.hbm.xml
<hibernate-mapping>
<class name="Fullname" table="fullname" schema="someSchema">
<composite-id name="id" class="FullnameId">
<key-property name="id" type="java.lang.Long">
<column name="ID" precision="5" scale="0" />
</key-property>
<key-property name="fromDate" type="java.util.Date">
<column name="FROM_DATE" length="7" />
</key-property>
</composite-id>
<property name="lastname" type="java.lang.String">
<column name="LASTNAME" length="160" not-null="true" />
</property>
<property name="firstname" type="java.lang.String">
<column name="FIRSTNAME" length="120" not-null="true" />
</property>
... fields deleted ......
<set name="Mhscode">
<key column="id"/>
<one-to-many class="Mhscode"/>
</set>
</class>
</hibernate-mapping>
mhscode.hbm.xml

<hibernate-mapping>
<class name="gov.loc.legis.hibernate.Mhscode" table="MHSCODE" schema="LISBSS">
<composite-id name="id" class="gov.loc.legis.hibernate.MhscodeId">
<key-property name="id" type="java.lang.Long">
<column name="ID" precision="5" scale="0" />
</key-property>
<key-property name="code" type="java.lang.String">
<column name="CODE" length="40" />
</key-property>
<key-property name="fromDate" type="java.util.Date">
<column name="FROM_DATE" length="7" />
</key-property>
</composite-id>
..... stuff deleted .......
<!-- unsure if I need another mapping back to fullname -->
</class>
</hibernate-mapping>

Stack trace:

%%%% Error Creating SessionFactory %%%%
org.hibernate.MappingException: Foreign key (FK68CE0405EF493335:MHSCODE [id])) must have same number of columns as the referenced primary key (fullname [ID,FROM_DATE])
at org.hibernate.mapping.ForeignKey.alignColumns(ForeignKey.java:90)
at org.hibernate.mapping.ForeignKey.alignColumns(ForeignKey.java:73)
at org.hibernate.cfg.Configuration.secondPassCompileForeignKeys(Configuration.java:1263)
at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1170)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1286)
at HibernateSessionFactory.<clinit>(HibernateSessionFactory.java:31)
at BaseHibernateDAO.getSession(BaseHibernateDAO.java:13)
at FullnameDAO.findByProperty(FullnameDAO.java:93)
at FullnameDAO.findByFirstname(FullnameDAO.java:107)
at TestSponsorFetchDriver.main(TestSponsorFetchDriver.java:22)


database: Oracle 9.2.0.8 (yes, I know it is old!)


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 16, 2008 4:39 am 
Beginner
Beginner

Joined: Tue Sep 09, 2008 5:42 am
Posts: 22
Location: Romania
Ciao,

Short response: Yes it is!

Long Response:

Go to this link: http://forum.hibernate.org/viewtopic.php?t=991318&highlight= and look how I suggested to map the composite-id in a separate class and how after that you can create a criteria over a single field from the composite-id.

Hope it helps.


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.