-->
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.  [ 3 posts ] 
Author Message
 Post subject: Child entities not deleted when calling clear on the collect
PostPosted: Mon Jun 15, 2009 4:06 am 
Newbie

Joined: Mon Jun 15, 2009 3:44 am
Posts: 2
Hi,

I'm having an issue with our entities mapping. Here is the entity definitions:

Here is the VideoDocument entity that is the owner entity:
Code:
@Entity
@Table(name="V_DOCUMENT")
public class VideoDocument {
   @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
   @JoinColumn(name="doc_ref", nullable =  false)
   public Set<VideoDocumentTitle> getTitles() { ... }
}


Here is the VideoDocumentTitle entity that provides multilingual support to our VideoDocument
Code:
@Entity
@Table(name="V_DOC_TITLES")
public class VideoDocumentTitle {
   private VideoDocumentTitleId id;

   @EmbeddedId
   @AttributeOverrides( {
   @AttributeOverride(name = "documentRef", column = @Column(name = "DOC_REF", nullable = false, length = 8)),
   @AttributeOverride(name = "langId", column = @Column(name = "LANG", nullable = false, length = 3)),
   @AttributeOverride(name = "titleQualifierId", column = @Column(name = "QUAL", nullable = false, precision = 22, scale = 0)) })
   public VideoDocumentTitleId getId() { return this.id; }

   public void setId(VideoDocumentTitleId id) { this.id = id; }   
}


Here is the composite key of the VideoDocumentTitle entity:

Code:
@Embeddable
public class VideoDocumentTitleId implements java.io.Serializable {

   private String documentRef;
   private String langId;
   private Long titleQualifierId;

   public boolean equals(Object compareTo) { ... }
   public int hashCode() { ... }


Where equals() and hashCode() are properly defined.

The issue I'm having is that if I execute the following code:

Code:
@Transactional(readOnly = false, propagation = Propagation.REQUIRED)
public void clearCollection(String reference) {
   VideoDocument video = getVideoDocument(reference)
   video.getTitles().clear(); // (1)
   // video.getThesaurusTerms().clear(); (2)
}


When this dummy method (to demonstrate the issue) is called, titles (1) are not removed from the database whereas the thesaurusTerms are properly removed. The difference between titles and thesaurusTerms is that thesaurusTerms has no composite key but instead a regular Id field.

Is there a limitation in Hibernate (I'm using 3.2.2.GA with 3.3.0.GA for annotations) with composite keys I'm not aware of?

Note: using a debugger, I can tell that when the code statement (1) is called, the collection is properly initialized and contains the titles attached to the VideoDocument and then marked as dirty.

Any clue about my problem? I believe it's a configuration problem but I tried many solutions and couldn't find one that removes the titles attached to a video.

Thanks for any help or pointers.


Top
 Profile  
 
 Post subject: Re: Child entities not deleted when calling clear on the collect
PostPosted: Mon Jun 15, 2009 9:47 am 
Regular
Regular

Joined: Thu Sep 06, 2007 2:22 am
Posts: 108
Location: Noida,India
Add below mapping in
Quote:
VideoDocument
entity.
Quote:
@org.hibernate.annotations.Cascade(
value = org.hibernate.annotations.CascadeType.DELETE_ORPHAN
)


like this-
@Entity
@Table(name="V_DOCUMENT")
public class VideoDocument {
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
@org.hibernate.annotations.Cascade(
value = org.hibernate.annotations.CascadeType.DELETE_ORPHAN
)
@JoinColumn(name="doc_ref", nullable = false)
public Set<VideoDocumentTitle> getTitles() { ... }
}


Top
 Profile  
 
 Post subject: Re: Child entities not deleted when calling clear on the collect
PostPosted: Mon Jun 15, 2009 10:10 am 
Newbie

Joined: Mon Jun 15, 2009 3:44 am
Posts: 2
Thanks a lot. That solved it.

I have a question though. For my understanding, why is it working without DELETE_ORPHAN when entities in a collection have a simple Id attribute (e.g. private Long Id;).

Indeed, my problem above only occurs when entities in the collection have a composite key.

Thanks again for your help.


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