-->
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.  [ 1 post ] 
Author Message
 Post subject: Custom Hibernate CascadeType.DELETE
PostPosted: Wed Mar 23, 2011 6:57 am 
Newbie

Joined: Sat Dec 11, 2010 8:49 am
Posts: 19
Hello,

I am interested is there any way to perform custom DELETE in Hibernate.

Here is situation:
I defined many-to-many relation between Album and Artist, so Album can have ONE or MANY Artists and
Artist can have ONE or MANY Albums.
Here is mapping in Artist:
@ManyToMany(targetEntity=Album.class, fetch=FetchType.LAZY)
@Cascade({ org.hibernate.annotations.CascadeType.PERSIST, org.hibernate.annotations.CascadeType.MERGE })
@JoinTable(name="album_artist", joinColumns={@JoinColumn(name="ArtistID")},
inverseJoinColumns={@JoinColumn(name="AlbumID")})
private Set<Album> albums = new HashSet<Album>();

Now if i modify Artist deleting some albums from set, only specified rows from album_artist table are removed which is ok.
If i delete Artist, artist will be deleted and all rows from album_artist table with this ArtistID and that is also what i want.
However i would like to delete also Album from album table IF AND ONLY IF that album HAS ONLY THAT ARTIST.
Contrary if that Album have other artists also, i don't want to delete album from Album table.

If i specify also org.hibernate.annotations.CascadeType.DELETE, then album will be deleted even if
it have other artists!

Is there any way to delete album only if album don't contain other artists?

Best regards.


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

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.