Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » Elements of List in @OneToMany with @OrderColumn are not being sorted
Elements of List in @OneToMany with @OrderColumn are not being sorted [message #523642] Sat, 27 March 2010 22:08 Go to next message
Igor Mukhin is currently offline Igor MukhinFriend
Messages: 14
Registered: July 2009
Junior Member
Hello,

I have following mappings:

@Entity
public class Country implements Serializable {

	@Id
	@Column(updatable=false)
	private String id;

	@OneToMany(mappedBy="country", cascade=CascadeType.ALL, orphanRemoval=true)
	@OrderColumn(name="OrderIdx")
	private List<CountryLocale> countryLocales;
	
	@ElementCollection
	@Column(name="TIMEZONE")
	@CollectionTable(
	        name="COUNTRY_TIMEZONE",
	        joinColumns=@JoinColumn(name="COUNTRY_ID", referencedColumnName="ID")
	  )
	@OrderColumn(name="OrderIdx")
	private List<String> timezones;
}

@Entity
@Table(name="COUNTRY_LOCALE")
@IdClass(CountryLocalePK.class)
public class CountryLocale implements Serializable {

	@Id
    @ManyToOne
    @JoinColumn(name="COUNTRY_ID")
    private Country country;
	@Id
	private String locale;
	
	@ElementCollection
	@Column(name="FALLBACK_LOCALE")
	@CollectionTable(
	        name="COUNTRY_LOCALE_FALLBACK",
	        joinColumns={
	    	        @JoinColumn(name="COUNTRY_ID", referencedColumnName="COUNTRY_ID"),
	    	        @JoinColumn(name="LOCALE", referencedColumnName="LOCALE")
	        }
	  )
	@OrderColumn(name="OrderIdx")
	private List<String> fallbackLocales;
}


Then i do the following:

    Country c = em.find(Country.class, "DE");
    for (String tz: cl.getTimezones()) {
        System.out.println(tz);
    }
    for (CountryLocale cl: cl.getCountryLocales()) {
        System.out.println(cl.getLocale());
    }


The timezones are printed in the correct order.
BUT the CountryLocale are printed unsorted! (in the same order the database put them into the resultset).
Is it a bug or do I do something wrong?

I tested it with eclipselink 2.0.1 and 2.1.0-M6.

Thanks
Igor
Re: Elements of List in @OneToMany with @OrderColumn are not being sorted [message #523918 is a reply to message #523642] Mon, 29 March 2010 19:46 Go to previous message
James Sutherland is currently offline James SutherlandFriend
Messages: 1939
Registered: July 2009
Location: Ottawa, Canada
Senior Member

The OneToMany should get ordered based on the index column "OrderIdx" is the table.

It could be a case issue. Try using "ORDERIDX".

Otherwise please include the SQL, data results, and resulting object order.


James : Wiki : Book : Blog : Twitter
Previous Topic:audit tracking
Next Topic:Issue with EclipseLink and Felix OSGi
Goto Forum:
  


Current Time: Thu Dec 18 04:16:20 GMT 2014

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

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