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: Cascade deletion of embeddable objects' collection
PostPosted: Wed Aug 29, 2012 4:09 am 
Newbie

Joined: Thu Jun 07, 2012 10:03 am
Posts: 8
Hi,

I have an entity A that has a collection of basic types (e.g. String). I use such a mapping because the strings associated to each instance of A depend on A's life cycle. If I want to remove an instance of A from the DB, I also want its associated Strings to be removed.

My mapping is as follows:

Code:
@Entity
public class A {

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;

    @ElementCollection(fetch = FetchType.EAGER)
    @CollectionTable(name = "AStrings", joinColumns = @JoinColumn(name = "id"))
    @Column(name = "strings", nullable = false)
    private Set<String> strings;
}


If I create an instance of A and add it some strings, then I can persist the instance using Session.save(myInstance). Both the instance of A and its associated Strings are persisted.

But, if I want to remove the same instance from the DB, using Session.delete(myInstance), I get a foreign key constraint error:

Quote:
Cannot delete or update a parent row: a foreign key constraint fails


But, I would expect the associated Strings to be automatically removed before removing the A's instance, but it seems it's not the case. I also didn't found a way to specify cascade rules.

I've also tried using @Cascade(CascadeType.DELETE) on the field strings, and it still doesn't help. By looking at the database, I don't see any ON DELETE policy for the concerned foreign key.

Is there something wrong with my configuration?

Thanks


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.