-->
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: one-to-many relation with composite_id on *many* side
PostPosted: Thu Aug 28, 2003 7:21 am 
Newbie

Joined: Thu Aug 28, 2003 7:14 am
Posts: 18
I have the next
scenario:

Two classes A and B, where A has an attribute of type B, i think this is an
ordinary many-to-one relationship, but the problem is that the id of the
class B is composed (composite-id), and in the declaration of a many-to-one
relationships in the maping file(hbm.xml) you can declare just one column to
match?

What is the right way to define mapping for this scenario? Currently I am getting

DEBUG, 2003-08-28 15:01:24,038, StringType, (NullableType.java:nullSafeSet:44), binding 'stam' to parameter: 1
DEBUG, 2003-08-28 15:01:24,038, LongType , (NullableType.java:nullSafeSet:38), binding null to parameter: 2
DEBUG, 2003-08-28 15:01:24,038, LongType , (NullableType.java:nullSafeSet:44), binding '1' to parameter: 3
DEBUG, 2003-08-28 15:01:24,088, SessionImpl, (SessionImpl.java:afterTransactionCompletion:447), transaction completion
net.sf.hibernate.HibernateException: SQL update or deletion failed (row not found)
at net.sf.hibernate.impl.NonBatchingBatcher.addToBatch(NonBatchingBatcher.java:25)
at net.sf.hibernate.persister.EntityPersister.update(EntityPersister.java:642)
at net.sf.hibernate.persister.EntityPersister.update(EntityPersister.java:611)
at net.sf.hibernate.impl.ScheduledUpdate.execute(ScheduledUpdate.java:31)
at net.sf.hibernate.impl.SessionImpl.executeAll(SessionImpl.java:2100)
at net.sf.hibernate.impl.SessionImpl.execute(SessionImpl.java:2062)
at net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2005)
at net.sf.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:57)
at com.digifuel.common.hibernate.HFlow.main(HFlow.java:110)
net.sf.hibernate.HibernateException: SQL update or deletion failed (row not found)


Thanks

Michael.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 28, 2003 2:13 pm 
Pro
Pro

Joined: Tue Aug 26, 2003 1:24 pm
Posts: 213
Location: Richardson, TX
I'm far from a Hibernate expert, but since I have recent experience with this (see http://forum.hibernate.org/viewtopic.php?t=61) I'll take a stab.

You can't reference only one (or any less than all) of the fields in a foreign key. At least, when I try to generate DDL from a mapping file, if my many-to-one relationships mismatch the number of fields in the key of the "one side" of the relationship, hbm2ddl throws an exception. (message "Foreign key must have same number of columns as referenced primary key")

You can define more than one column for the relationship in a many-to-one mapping, though.

Try something like this:

Code:
<class name="A" table="A">
  <many-to-one name="B" outer-join="false" class="B">
    <column name="key_column_1"/>
    <column name="key_column_2"/>
  </many-to-one>
</class>


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.