Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » Maintain Insert order while inserting in a table
Maintain Insert order while inserting in a table [message #991698] Thu, 20 December 2012 02:16 Go to next message
Zaraki r is currently offline Zaraki rFriend
Messages: 2
Registered: March 2012
Junior Member
Hi,
This is a problem I am running into.
We are using eclipselink 2.3.2.
I am adding snippets of what our entities look like



@Entity
@Table(name = "entity")
@AttributeOverride(name = "id", column = @Column(name = "entityId"))
public class EntityA  {
    private static final long serialVersionUID = 2337915639426837746L;

    @Basic
    @Column(name = "name")
    protected String name;


    @OneToMany(mappedBy = "entity", fetch = FetchType.EAGER, cascade = CascadeType.ALL,orphanRemoval=true)
    private List<EntityB> setAssignmentEntities = new ArrayList<EntityB>();


}



@Entity
@Table(name = "entity_set")
public  class EntityB implements Serializable {

    private static final long serialVersionUID = -7050818401379732731L;
	
	
	    @ManyToOne
    @JoinColumns({
            @JoinColumn(name = "entityId", referencedColumnName = "entityId", updatable = false, insertable = false) })
    EntityA entity;
	@Id
    @Column(name = "entityName")
    private String entityName;


    @Id
    @Column(name = "fieldId")
    private int fieldId;


}





We do not have any Order by clause, however upon querying the
db, it is seen that the inserts to the EntityB were made as if sorted on the
primary key(fieldId).
For ex, If I insert entities with fieldId's
53
2
7

Now if I query the db I get the results in order
2
7
53

It is very important for our application that the original order is retained.
Is there any way to retain the order of the inserts?

Thanks
Re: Maintain Insert order while inserting in a table [message #991927 is a reply to message #991698] Thu, 20 December 2012 13:54 Go to previous message
khalil haddad is currently offline khalil haddadFriend
Messages: 12
Registered: November 2012
Junior Member
You can take a look at this page : http://wiki.eclipse.org/EclipseLink/Examples/JPA/Collectionordering

It explains how to use the @OrderBy JPA 1.0 annotation.
Previous Topic:show_sql turn off at runtime
Next Topic:JAXB with Eclipse RCP
Goto Forum:
  


Current Time: Wed Dec 17 19:54:23 GMT 2014

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

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