Hibernate version:
3.2.0
Hello, i'm doing a merge of an entity that has a @OnetoMany association:
Code:
@Entity
@SequenceGenerator(name = "gen_productionperiod_id", sequenceName = "gen_productionperiod_id", allocationSize=1)
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
public abstract class ProductionPeriod implements Serializable {
private static final long serialVersionUID = 1L;
@Id()
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "gen_productionperiod_id")
private Long id;
@OneToMany(fetch=FetchType.EAGER, cascade={CascadeType.MERGE, CascadeType.MERGE})
private List<Event> events;
[...]
}
and here's the connected entity:
Code:
@SequenceGenerator(name = "gen_event_id", sequenceName = "gen_event_id", allocationSize=1)
@Entity()
@Table(name = "event")
public class Event implements Serializable {
private static final long serialVersionUID = 1L;
@Id()
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "gen_event_id")
private Long id;
[...]
}
My problem is that when i merge the ProductionPeriod entity (to be precise i merge a subclass as it is abstract), all the events are deleted and inserted
I think that this is done to preserve the order of the list.
Is there a way to optimize this in order to avoid all that delete and insert stuff? The order of insertion should be sufficient to preserve the temporal order that i need if a real sequence generator is used.