hibernate 4.3.0 @OneToMany orphanRemoval=true leaves orphans

369 Views Asked by At

I found a lot of discussions on orphanRemoval=true option still leaving orphans, however I do not seem to find the right answer for my problem.

I have a Connector class that has a OneToMany relation on a List of UniqueProperty class

@OneToMany(cascade = CascadeType.ALL, orphanRemoval=true)
@LazyCollection(LazyCollectionOption.FALSE)
private List<UniqueProperty> uniqueProperties;

UniqueProperty has this definition:

@Id
@Column(name = "id", length = 200, unique = true, nullable = false)
private String id;
private String name;
private String type;
@Column(unique=true)
private String value;

protected UniqueProperty(){}

I use a PostgreSQL DB. When I create a new Connector and add a UniqueProperty (name, valueA), it creates one row in connector_uniqueproperty table, and one row in uniqueproperty table. When I create a new Connector instance with same ID as one before (new hibernate session) and this time do not add the Unique Property, the session.saveOrUpdate(connector) call does remove the related row from connector_uniqueproperty, but leaves the related row in uniqueproperty table (now an orphan).

Any suggestions on why this happens?

0

There are 0 best solutions below