[hibernate-issues] [Hibernate-JIRA] Commented: (HHH-572) Repeated columns rejected in a collection of composite elements

greg jablonski (JIRA) noreply at atlassian.com
Mon Aug 7 14:17:20 EDT 2006


    [ http://opensource.atlassian.com/projects/hibernate/browse/HHH-572?page=comments#action_23868 ] 

greg jablonski commented on HHH-572:
------------------------------------

Is there a workaround for the case where you want the many-to-one to be the derived association?  I'm trying to do this because my many-to-one is mapped with not-found="ignore", and the property mapping to the same column is that foreign key, and I want to have access to the foreign key value regardless of whether the association is null or not, and a formula won't let me save that property if the many-to-one is null.

What I want to do is this:

<set name="siblings" table="SIBLINGS">
        <key column="child_id" />
        <composite-element class="Child">
                <property name="foo" column="foo">
                <property name="siblingId" column="sibling_id" />
                <many-to-one name="sibling" column="sibling_id" class="Child" update="false" insert="false" not-found="ignore" />
        </composite-element>
</set>

(I realize this looks a little strange, but SIBLING is really a direction-specific many-to-many join table augmented with "foo" in the example case.)  Thanks.

> Repeated columns rejected in a collection of composite elements
> ---------------------------------------------------------------
>
>          Key: HHH-572
>          URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-572
>      Project: Hibernate3
>         Type: Bug

>     Versions: 3.0.5
>  Environment: JRE 1.4.2_08
>     Reporter: Emmanuel Bourg
>     Assignee: Gavin King
>     Priority: Minor

>
>
> Repeating a column in a collection of composite elements triggers an error when the mapping is parsed, even if the property with the repeated column has the insert and update attributes set to false:
>     <set name="children" table="CHILDREN">
>       <key column="PARENT_ID"/>
>       <composite-element class="Child">
>         <property name="parentId" column="PARENT_ID" insert="false" update="false" />
>       </composite-element>
>     </set>
> or
>     <set name="roles" table="ROLE">
>       <key column="PARENT_ID"/>
>       <composite-element class="Role">
>         <many-to-one name="child" class="Child"/>
>         <property name="childId" column="CHILD_ID" insert="false" update="false" />
>       </composite-element>
>     </set>
> Hibernate throws this exception:
> org.hibernate.MappingException: Repeated column in mapping for collection: Parent.children column: PARENT_ID
>     at org.hibernate.mapping.Collection.checkColumnDuplication(Collection.java:275)
>     at org.hibernate.mapping.Collection.checkColumnDuplication(Collection.java:298)
>     at org.hibernate.mapping.Collection.validate(Collection.java:255)
>     at org.hibernate.mapping.Set.validate(Set.java:19)
>     at org.hibernate.cfg.Configuration.validate(Configuration.java:817)
>     at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:976)
> a workaround is to use a formula:
>     <set name="children" table="CHILDREN">
>       <key column="PARENT_ID"/>
>       <composite-element class="Child">
>         <property name="parentId" formula="PARENT_ID"/>
>       </composite-element>
>     </set>
> This works fine with the fix for HHH-539

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://opensource.atlassian.com/projects/hibernate/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira




More information about the hibernate-issues mailing list