[hibernate-issues] [Hibernate-JIRA] Commented: (HHH-2710) Cannot specify on-delete="cascade" for a map or a set with just one element

Sergey (JIRA) noreply at atlassian.com
Thu Aug 6 11:38:15 EDT 2009


    [ http://opensource.atlassian.com/projects/hibernate/browse/HHH-2710?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=33722#action_33722 ] 

Sergey commented on HHH-2710:
-----------------------------

I let myself to suggest swap places of !isInverse() || !isOneToMany() in if statement so that this will work also for unidirectional @OneToMany associations where there is no inverse="true"(XML) / mappedBy(annotations) side.

> Cannot specify on-delete="cascade" for a map or a set with just one element
> ---------------------------------------------------------------------------
>
>                 Key: HHH-2710
>                 URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-2710
>             Project: Hibernate Core
>          Issue Type: Improvement
>          Components: core
>    Affects Versions: 3.2.4
>            Reporter: Gerald Klopp
>            Priority: Minor
>         Attachments: hibernate2710.zip, patch.txt
>
>
> I'd like to specify the on-delete="cascade" attribute for a map or for a set with just one element.
> When I try to do this, I get the following exception :
> Initial SessionFactory creation failed.org.hibernate.MappingException: only inverse one-to-many associations may use on-delete="cascade"
> The on-delete="cascade" attribute can be specified for more complex relationships like one-to-many. But it seems that the case of a simple map or set is not covered.
> - Mapping document example:
> <hibernate-mapping>
>     <class name="Document" table="DOCUMENT">
>         <id name="id" column="DOCUMENT_ID">
>             <generator class="native" />
>         </id>
>         <map name="titles" table="DOCUMENT_TITLE" lazy="false">
>             <key column="DOCUMENT_ID" on-delete="cascade" />
>             <index column="LANGUAGE" type="string" />
>             <element column="TITLE" type="text" not-null="true" />
>         </map>
>         <set name="references" table="DOCUMENT_REFERENCE" lazy="false">
>             <key column="DOCUMENT_ID" on-delete="cascade" />
>             <element type="string" column="REFERENCE" />
>         </set>
>     </class>
> </hibernate-mapping>
> - Exception stack trace :
> Initial SessionFactory creation failed.org.hibernate.MappingException: only inverse one-to-many associations may use on-delete="cascade": Document.references
> Exception in thread "main" java.lang.ExceptionInInitializerError
>    at fr.gklopp.test.hibernate3.util.HibernateUtil.<clinit>(HibernateUtil.java:17)
>    at fr.gklopp.test.hibernate3.simple.DocumentManager.createAndStoreDocument(DocumentManager.java:23)
>    at fr.gklopp.test.hibernate3.simple.DocumentManager.main(DocumentManager.java:68)
> Caused by: org.hibernate.MappingException: only inverse one-to-many associations may use on-delete="cascade": fr.gklopp.test.hibernate3.simple.Document.references
>    at org.hibernate.mapping.Collection.validate(Collection.java:267)
>    at org.hibernate.mapping.Set.validate(Set.java:19)
>    at org.hibernate.cfg.Configuration.validate(Configuration.java:1106)
>    at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1287)
>    at fr.gklopp.test.hibernate3.util.HibernateUtil.<clinit>(HibernateUtil.java:13)
>    ... 2 more
> - Database : Oracle 10

-- 
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