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,
cascade = { CascadeType.ALL })
public Set<PlaceCan> getPlaceCans ();
@Entity
@Table(name = "cans")
public class Can
{
private Set<PlaceCan> placeCans;
@OneToMany(mappedBy="can", cascade = CascadeType.ALL)
public Set<PlaceCan> getPlaceCans ()
@Entity
public class PlaceCan
{
private Long id;
private Place place;
private Can can;
private int quantity;
@Column(name="idPlaceCan")
@Id @GeneratedValue(strategy = GenerationType.AUTO)
public Long getId()
@ManyToOne(cascade=CascadeType.ALL)
@JoinColumn(name="idPlace")
public Place getPlace()
@ManyToOne(cascade=CascadeType.ALL)
@JoinColumn(name="idCan")
public Cubo getCan()
Name and version of the database you are using: mySql 5
Pretty typical mapping for this kind of situation -- an association table that has association info. In this case, every Place can have x number of Cans (garbage cans, that is ...), and the association info is 'quantity'.
When I save a Place object, deletes and updates are not persisted. I see updates to the 'placecan' table I can't see the actual values since Hibernate is using PreparedStatements, all I see are '?' where the values will be substituted.
At any rate, no changes are persisted. And if I delete, they just re-appear. I tried changing Place like this:
Code:
@OneToMany(mappedBy="place", fetch = FetchType.EAGER)
@org.hibernate.annotations.Cascade(
{org.hibernate.annotations.CascadeType.ALL,
org.hibernate.annotations.CascadeType.DELETE_ORPHAN})
public Set<PlaceCan> getPlaceCans ()
... but with this code I don't even see update lines in the SQL log and if I delete I get this error:
Quote:
deleted object would be re-saved by cascade (remove deleted object from associations)
Can someone please tell me what I am doing wrong? I've been at this for days, no end in sight.
Thank you,
Bob