[
http://opensource.atlassian.com/projects/hibernate/browse/HHH-2710?page=c...
]
Cédric Chabanois commented on HHH-2710:
---------------------------------------
Please ignore previous comment . I used getKey() instead of getElement() ...
With Hibernate 3.2.5, I think this can be corrected by replacing in
org.hibernate.mapping.Collection :
"
public void validate(Mapping mapping) throws MappingException {
if ( getKey().isCascadeDeleteEnabled() && ( !isInverse() || !isOneToMany() ) ) {
throw new MappingException(
"only inverse one-to-many associations may use on-delete=\"cascade\":
"
+ getRole() );
}
[...]
"
by
"
public void validate(Mapping mapping) throws MappingException {
if ( getKey().isCascadeDeleteEnabled() ) {
if (!(getElement() instanceof SimpleValue) && ( !isInverse() || !isOneToMany() ) )
{
throw new MappingException(
"only inverse one-to-many associations may use on-delete=\"cascade\":
"
+ getRole() );
}
}
[...]
"
The table is correctly created (with an "ON DELETE CASCADE") and I can now use a
bulk delete.
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: Hibernate3
Issue Type: Improvement
Components: core
Affects Versions: 3.2.4
Reporter: Gerald Klopp
Priority: Minor
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....
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira