-->
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.  [ 4 posts ] 
Author Message
 Post subject: deleting child entity
PostPosted: Wed Jan 27, 2010 9:26 am 
Newbie

Joined: Wed Jan 14, 2009 7:25 pm
Posts: 5
Hello All,

I am having a problem when I set null to a manytoone relation and persist the object, the child entity is not deleted.

For example with the following code:

Code:
@Entity
public class Ad{

   @ManyToOne(cascade=CascadeType.ALL)
   private Action action;

... setters getters other things...
}


so this Ad class will have a property called action. My Action class and its child classes are as follows:

Code:
@Entity
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)

public abstract class Action{
...
}

@Entity
public class AudioAction extends Action {
}



@Entity
public class VideoAction extends Action {
}


so think of following scenario: I have an Ad object. it has a VideoAction object. They all persisted.

When user tries to update the Ad object, and sets a new AudioAction object for example, the DB is updated with the correct data. but the old, orphan VideoAction still remains in the DB as there is no reference to it.

How can I make sure old VideoAction is deleted when I set another Action object, or when I set null to the Ad's action property?

Thanks,

Yigit


Top
 Profile  
 
 Post subject: Re: deleting child entity
PostPosted: Wed Feb 10, 2010 1:58 am 
Newbie

Joined: Wed Jan 14, 2009 7:25 pm
Posts: 5
anyone?


Top
 Profile  
 
 Post subject: Re: deleting child entity
PostPosted: Wed Feb 10, 2010 3:44 am 
Expert
Expert

Joined: Wed Mar 03, 2004 6:35 am
Posts: 1240
Location: Lund, Sweden
Quoted from the Hibernate documentation (http://docs.jboss.org/hibernate/stable/ ... -manytoone):

Quote:
Note that single valued, many-to-one and one-to-one, associations do not support orphan delete.


In other words, you'll have to call session.delete() in your own code.


Top
 Profile  
 
 Post subject: Re: deleting child entity
PostPosted: Fri Oct 01, 2010 9:06 am 
Newbie

Joined: Mon Dec 01, 2003 12:41 pm
Posts: 12
Location: Aix en Provence, France
Ok I check with version 3.5.5 and it does NOT work.
But Why does JIRA says this feature has been corrected ?
http://opensource.atlassian.com/project ... e/HHH-4726

I tried with the following XML mapping :

<hibernate-mapping>
<class name="business.hb.Address" schema="public" table="address">
<id name="id" type="long">
<column name="id" />
<generator class="foreign">
<param name="property">person</param>
</generator>

</id>
<version generated="never" name="version" type="int">
<column name="version" not-null="true" />
</version>
<property generated="never" lazy="false" name="description"
type="string">
<column length="50" name="description" />
</property>
<one-to-one name="person" class="business.hb.Person" constrained="true" />
</class>
</hibernate-mapping


<hibernate-mapping>
<class name="business.hb.Person" schema="public" table="person">
<id name="id" type="long">
<column name="id" />
<generator class="org.hibernate.id.enhanced.TableGenerator">
<param name="table_name">ID_GENERATOR</param>
<param name="value_column_name">GEN_VALUE</param>
<param name="segment_column_name">GEN_ID</param>
<param name="segment_value">PERSON_ID</param>
<param name="increment_size">50</param>
<param name="optimizer">pooled</param>
<param name="max_lo">100</param>
</generator>
</id>
<version generated="never" name="version" type="int">
<column name="version" not-null="true" />
</version>
<property generated="never" lazy="false" name="name" type="string">
<column length="50" name="name" />
</property>
<one-to-one name="address" class="business.hb.Address" cascade="all,delete-orphan" constrained="true"/>
</class>
</hibernate-mapping

_________________
Gauthier P.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.