Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » Order of inserting List items(the order in which entities stored in List are inserted is weird)
Order of inserting List items [message #880034] Fri, 01 June 2012 10:09 Go to next message
devel devel is currently offline devel develFriend
Messages: 2
Registered: June 2012
Junior Member
Hallo,
i have an entity MainHarvestStatistics
@Entity(name = "main_harvest_statistics")
@Table(name = "main_harvest_statistics", schema = "harvest")
public class MainHarvestStatistics implements Serializable {
	private static final long serialVersionUID = 1L;

	@Column(name = "start_time")
	@Temporal(TemporalType.TIMESTAMP)
	private Date startTime;

	@Column(name = "end_time")
	@Temporal(TemporalType.TIMESTAMP)
	private Date endTime;

	@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
	@JoinColumn(name = "harvest_id", referencedColumnName = "harvest_id")
	@OrderBy("absFilePath ASC")
	private List<HarvestedFile> harvestedFiles;

Here i store an ordered List of harvestedFiles. However the harvestedFiles are not inserted into DB in their order. How could i force eclipselink to insert them in the order they are stored in List? I use Eclipselink 2.2 and postgresql
Re: Order of inserting List items [message #880186 is a reply to message #880034] Fri, 01 June 2012 15:21 Go to previous messageGo to next message
Chris Delahunt is currently offline Chris DelahuntFriend
Messages: 1389
Registered: July 2009
Senior Member
I do not believe you can - cascade persist operates on all entities in the list, but the order of statements is up to the provider to determine. If you wish a particular order, the only way to garantee that in JPA is by forcing it with a flush. In this case you will need to persist each HarvestedFile directly and call flush after each. Otherwise, most JPA providers will attempt to reorder statements around for optimization and referential integrity.

Is there a particular reason you need inserts in order?

Best Regards,
Chris
Re: Order of inserting List items [message #880191 is a reply to message #880186] Fri, 01 June 2012 15:38 Go to previous messageGo to next message
devel devel is currently offline devel develFriend
Messages: 2
Registered: June 2012
Junior Member
Yes i need to keep the order of the List for my app to work. I can of course think of many workarounds, but was hoping i don't have to Sad
Anyway, I will use the obvious option to persist the Objects in list separately, was just hoping i don't have to. I learned something new about JPA, thanks.
Re: Order of inserting List items [message #880213 is a reply to message #880191] Fri, 01 June 2012 16:28 Go to previous message
Chris Delahunt is currently offline Chris DelahuntFriend
Messages: 1389
Registered: July 2009
Senior Member
Sorry I do not quite understand how your app is dependent on the insert order to work. The ordering of the collection is one thing, the order of inserts is something else. Can you explain a bit more what you mean?
Previous Topic:Generate schema from MOXY external bindings-oxm.xml file...
Next Topic:Changes from EntityListeners not propagated in commit
Goto Forum:
  


Current Time: Fri Mar 29 11:13:52 GMT 2024

Powered by FUDForum. Page generated in 0.02361 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top