-->
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: Why Hibernate cascades changes when no Cascade is specified?
PostPosted: Fri Oct 26, 2007 5:52 am 
Newbie

Joined: Sat Jan 14, 2006 8:03 pm
Posts: 18
Hibernate version: 3.2.5.ga

Mapping documents:

@Entity
@Table(name = "places")
public class Place
{

private Set<PlaceCan> placeCans;

@OneToMany(mappedBy="place", fetch = FetchType.EAGER)
public Set<PlaceCan> getPlaceCans ();



Well, I got no love for my last post http://forum.hibernate.org/viewtopic.php?t=980711&sid=25396b23346007a755ab13e872d6dda3 about why Hibernate isn't persisting changes or deletes in my OneToMany relation, so I have decided to just do it manually. Whenever I save a Place object my plan is to:

1. Load the existing Place (if it's not new)
2. Iterate over its PlaceCans and delete each one
3. Save the new/modified Place
4. Iterate over its PlaceCans and save each one

In order to do this I need to turn off cascading so Hibernate doesn't try to do anything with associated PlanCan objects when I call place.save(). But it is anyway.

When I call place.save() on a new Place it fails trying to save associated PlanCan objects because since I still haven't saved the Place object, I don't have an idPlace to stick in the PlaceCan object, thus it fails.

When I call place.save() on an existing Place I get an error: saying 'No row with the given identifier exists'. It seems Hibernate is trying to modify the associated PlaceCan objects, but since I just deleted them, it fails.

I thought if you don't specifically tell Hibernate to Cascade, it does nothing. According to the JPA docs, 'By default, JPA does not cascade any persistence operations to the target of the association.'

So what gives?

Many, and I mean many thanks for any tips.

Bob


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 29, 2007 3:56 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
I tried to answer in the original post

_________________
Emmanuel


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.