-->
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.  [ 1 post ] 
Author Message
 Post subject: many-to-many and natural composite-id
PostPosted: Tue Apr 25, 2006 1:17 pm 
Newbie

Joined: Tue Apr 25, 2006 12:46 pm
Posts: 1
Location: Victoria, Canada
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version: 3.1

Mapping documents:

<class
name="ApplicationRole"
table="APPLICATION_ROLE">
<composite-id>
<key-property
name="applicationAcronym"
column="APPLICATION_ACRONYM">
</key-property>
<key-property
name="roleName"
column="ROLE_NAME">
</key-property>
</composite-id>

<set
name="actions"
table="ACTION_LNK">
<key>
<column name="APPLICATION_ACRONYM "/>
<column name="ROLE_NAME"/>
</key>
<many-to-many class="Action">
<column name="APPLICATION_ACRONYM"/>
<column name="ACTION_NAME"/>
</many-to-many>
</set>
...
</class>

<class
name="Action"
table="ACTION">
<composite-id>
<key-property
name="applicationAcronym"
column="APPLICATION_ACRONYM">
</key-property>
<key-property
name="actionName"
column="ACTION_NAME">
</key-property>
</composite-id>

...
</class>





Hi, I love Hibernate, but I seem to run into difficulties when I
try to write code against an already-existing database schema which
uses a lot of "natural" keys.

A row in the APPLICATION_ROLE table is uniquely identified by
APPLICATION_ACRONYM+ROLE_NAME columns.

A row in the ACTION table is uniquely identified by
APPLICATION_ACRONYM+ACTION_NAME.

A row in ACTION_LNK is uniquely identified by
ROLE_NAME+APPLICATION_ACRONYM+ACTION_NAME.

A row in APPLICATION_ROLE table is mapped to the Java object
'ApplicationRole'.

A row in the ACTION table is mapped to the Java object 'Action'.

The hibernate mapping above successfully maps a set of 'Action' objects
to an 'ApplicationRole' object, but it does so by cheating; I have added
an extra space in a column name to defeat Hibernate's duplicate column
checking:

<column name="APPLICATION_ACRONYM "/>

instead of

<column name="APPLICATION_ACRONYM"/>

My question is this: what is the "correct" way to do this mapping?

If I take the extra space out of the mapping I get the following exception:

org.hibernate.MappingException: Repeated column in mapping for collection: ApplicationRole.actions column: APPLICATION_ACRONYM


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.