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