-->
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.  [ 2 posts ] 
Author Message
 Post subject: Question on OneToMany relation with Map (weired behaviour)
PostPosted: Sat Feb 02, 2008 5:28 am 
Newbie

Joined: Wed Nov 07, 2007 3:58 pm
Posts: 15
Hi,

i have the following mapping:

Code:
@OneToMany(cascade={CascadeType.ALL}, fetch = FetchType.LAZY)
@MapKey(name="mapKey")
private Map<String, NonFunctionalProperty> nonFunctionalProperties = new HashMap<String, NonFunctionalProperty>();



    [list=]when i persist my class- the map is persistet well :)
    [list=]when i delete my class- the map is deleted well :)
BUT when i remove an element of the map - the element is mot deleted - what will rais at a later point in my code an constrained violation :(
[/list]

Ok - is there an option to CASCADE the remove-Operation of an item of the map ?

When not - is the only way to solve my problem to delete the item myself with a dao ?

Regards, Tobias


Top
 Profile  
 
 Post subject:
PostPosted: Sat Feb 02, 2008 6:48 am 
Regular
Regular

Joined: Mon Aug 20, 2007 6:47 am
Posts: 74
Location: UK
Hi,

I think you need to use CascadeType.DELETE_ORPHAN in addition to CascadeType.ALL (the org.hibernate.annotations version rather than javax.persistance).

It's my understanding that hibernate will not assume that an entity can be safely deleted when it's removed from a collection, as it doesn't know if the entity is being used elsewhere (entities have their own independant lifecycle). DELETE_ORPHAN is the way of telling hibernate that you don't want to keep persisting an entity that's been removed from an association.

-Paul


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