-->
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.  [ 6 posts ] 
Author Message
 Post subject: Can't use on-delete for key in a collection map?
PostPosted: Sun Jun 19, 2005 5:26 am 
Beginner
Beginner

Joined: Wed Sep 15, 2004 3:14 am
Posts: 35
Hibernate version: 3.0.5

Mapping documents:

Code:
<map
    name="properties"
    table="UserProperty"
    lazy="true"
    sort="unsorted"
    cascade="save-update"
    batch-size="10"
>

    <key
   column="userId"
   on-delete="cascade"
    >
    </key>

    <index
   column="name"
   type="java.lang.String"
   length="100"
    />

    <element
   column="value"
   type="java.lang.String"
   length="255"
   not-null="true"
   unique="false"
    />
</map>


Full stack trace of any exception that occurs:

Code:
ERROR [main] ContextLoader.initWebApplicationContext(177) | Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in URL [jar:file:/C:/Apache/tomcat/webapp/WEB-INF/lib/dao.jar!/META-INF/applicationContext-hibernate.xml]: Initialization of bean failed; nested exception is org.hibernate.MappingException: only inverse one-to-many associations may use on-delete="cascade": com.example.dao.User.properties org.hibernate.MappingException: only inverse one-to-many associations may use on-delete="cascade": com.example.dao.User.properties
   at org.hibernate.mapping.Collection.validate(Collection.java:236)
   at org.hibernate.mapping.IndexedCollection.validate(IndexedCollection.java:67)
   at org.hibernate.cfg.Configuration.validate(Configuration.java:841)
   at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1000)
   at org.springframework.orm.hibernate3.LocalSessionFactoryBean.newSessionFactory(LocalSessionFactoryBean.java:746)


Name and version of the database you are using: PostgreSQL 7.4

Collection Map is a one-to-many associations, why is it throwing the exception? I also tried to put in the inverse attribute = true and it still throws the same exception.

A bug?


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jun 19, 2005 5:30 am 
Beginner
Beginner

Joined: Wed Sep 15, 2004 3:14 am
Posts: 35
Whenever I do a batch delete (a list of users), I get an PostgreSQL foreign key constraints violation exception for the relation UserProperties.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 20, 2005 2:39 am 
Newbie

Joined: Wed Jun 15, 2005 4:58 am
Posts: 6
I have exactly the same problem.
In my case the 'cascade' rule in the collection is even stronger - 'all-delete-orphan'. And still hbm2ddl does not generate 'on delete cascade' in the schema.

The way I get around this [for now] is via an Ant task that modifies the schema to include 'on delete cascade' - a hack, to say the least.

Slightly related question - why do you use 'save-update' in the collection 'cascade'? It would seem to me that component's lifecycle is owned by the parent and it cannot exist outside of its parent. So would't the only valid 'cascade' methods be 'delete-orphan' and 'all-delete-orphan'?

Shouldn't hbm2ddl always generate 'on delete cascade' for component collections?

If you do find the solution to this, please post it here!


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 31, 2006 3:37 am 
Newbie

Joined: Wed May 31, 2006 3:19 am
Posts: 2
Same problem here:


Code:
<class name="theClass" table="the_class_table">
    <id name="rowId" column="rid" type="integer">
      <generator class="native" />
    </id>
    <map name="theMap" batch-size="50" lazy="true" table="the_map_table">
      <key foreign-key="theForeignKey" on-delete="cascade">
        <column name="the_row_id" />
      </key>
      <map-key column="key" type="string" />
      <element column="value" type="double" />
    </map>
</class>


For performance reasons, be want to use a delete query like

Code:
delete from theClass where ...


This of course only works if the dependant rows in the_map_table
are deleted at the same time.
Now, with this mapping SchemeExport correctly creates 'on delete cascade' clauses in the ddl's. So far, so good, but Hibernate won't
accept the on-delete="cascade", throwing the exception mentioned
in the first post of this thread.
Can anybody tell me why this restriction for on-delete="cascade" exists on maps? I specially wonder because if you manually add 'on delete cascade' to the ddl's, everything seems to work perfectly fine.
Is this a bug? Any known workarounds?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 09, 2009 10:34 am 
Newbie

Joined: Thu Oct 23, 2008 6:38 am
Posts: 2
I've just come across the same issue, just wondered if anyone had found a solution to this?


Top
 Profile  
 
 Post subject: annoing hibernate developers
PostPosted: Fri Mar 13, 2009 8:50 am 
Newbie

Joined: Fri Nov 30, 2007 8:57 am
Posts: 1
there is allready bug report for this situation. but nobody want repair this stupid limitation. I don't know any rational reason for this and I don't know any rationale solution.[/url]


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

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.