Hibernate version:3.2.5
Name and version of the database you are using: MySql 5
I have the following:
@Entity
@Table(name = "establishments")
public class Establishment {
...
private Set<EstablishmentContainer> establishmentContainers;
...
@OneToMany(mappedBy="establishment", fetch = FetchType.EAGER, cascade = { CascadeType.ALL })
public Set<EstablishmentContainer> getEstablishmentContainers ()
{
return establishmentContainers;
}
@Entity
@Table(name = "containers")
public class Container {
...
private Set<EstablishmentContainer> establishmentContainers;
...
@OneToMany(mappedBy="container")
public Set<EstablishmentContainer> getEstablishmentContainers ()
{
return establishmentContainers;
}
@Entity
public class EstablishmentContainer {
...
private Establishment establishment;
private Container container;
...
@ManyToOne
@JoinColumn(name="idEstablishment")
public Establishment getEstablishment()
{
return establishment;
}
@ManyToOne
@JoinColumn(name="idContainer")
public Container getContainer()
{
return container;
}
The user can add Containers from the establishment.jsp page. When I save, the collection is properly updated but Hibernate is not deleting the existing EstablishmentContainer objects. So if I start out with 2 and don't change anything, I now have 4! If I add one I have 5!
Do I have to somehow manually delete the existing EstablishmentContainers before saving? Just before calling establishment.save() I see that my Establishment object has the correct number of EstablishmentContainers. But when I save I have the exisiting EstablishmentContainers + any new ones I may have added or modified.
Can someone tell me how to prevent this?
Thanks!
Bob
|