-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: updating an ordered list
PostPosted: Mon Jan 08, 2007 7:17 am 
Newbie

Joined: Thu May 05, 2005 5:54 am
Posts: 17
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.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 08, 2007 1:36 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
don't use a bag collection (check the documentation)

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 09, 2007 5:28 am 
Newbie

Joined: Thu May 05, 2005 5:54 am
Posts: 17
uhmm...

Code:
Note

If you forgot to set @IndexColumn, the bag semantic is applied.


yep.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.