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.