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