I have a relatively complex entity. Something like this:
@Entity
public class MyEntity {
/// some fields
///...
@OneToMany(/*cascade = CascadeType.ALL, */fetch = FetchType.EAGER)
@Fetch(FetchMode.SELECT)
@Cascade({CascadeType.ALL})
protected Set<ParameterValue> parameterValues
//...
}
@Entity
public class ParameterValue {
// ...
@ManyToOne(fetch = FetchType.EAGER)
@Cascade({org.hibernate.annotations.CascadeType.MERGE, org.hibernate.annotations.CascadeType.SAVE_UPDATE, org.hibernate.annotations.CascadeType.REFRESH})
private Parameter parameter
}
MyEntity has String id, ParameterValue has generated long Id and Parameter has string id
My Entity has parameter values, each of whose has parameter, which is shared among other parameter values from different entities
Parameter is abstract class with different implementations
My problem is that when I call hibernate session saveOrUpdate for such objects 1) it is very slow 2) sometimes I receive org.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the session: [com.xxx.entities.content.EnumParameter#-1672482954]
What is correct way to save/update such entities ?
I inherited the schema from previous developer, so if it is required to simplify saving, I can change it