-->
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: Composite-ID problem...
PostPosted: Thu Sep 04, 2003 12:52 pm 
Newbie

Joined: Thu Sep 04, 2003 12:38 pm
Posts: 3
Location: Oslo
Hello!

I'm having a small problem with a database that I'm trying to read from with Hibernate. The mapping-xml for one of the classes looks like this:
Code:
<hibernate-mapping>
<class name="UserGroupRole" table="UserGroupRole">
  <composite-id name="pkObject" class="UserGroupRolePk">
   <key-many-to-one name="userGroup" class="UserGroup">
    <column name="userGroup"/>
    <column name="applicationID"/>
   </key-many-to-one>
   <key-many-to-one name="userRole" class="UserRole">
    <column name="userRole"/>
    <column name="applicationID"/>
   </key-many-to-one>
  </composite-id>
</class>
</hibernate-mapping>


It's a part of a many-to-many relationship where one of the columns is used as a part of the primary key on both sides. When hibernate tries to read this it says that the class should be mapped with insert="false" update="false". That would have been possible if it wasn't for that the applicationID-field is a part of the primary key. Is there a way to work around this problem? A normal many-to-one relationship supports these attributes, but not the key-many-to-one.

I'm currently trying to run this with Hibernate 2.1 beta 2, but I get the same kind of errors with the latest stable release.

...and yes, I know this kind of db-design stinks but the actual model looks a lot worse than the simplified version I've put up here.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 04, 2003 9:54 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Change your object model to have:


* a composite-id class that has only <key-property>s, no <key-many-to-one>s (key-many-to-ones are a pain to work with anyway)

* some ordinary <many-to-one>s mapped with insert="false" update="false"


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.