Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [eclipselink-users] Sort/Ordering of OneToMany relationship

OrderBy is normally done in the mapping.

Add the annotation to your OneToMany,
@OrderBy("x")


DeSilentio wrote:
> 
> Hi,
> 
> I'm new to Eclipselink (and the JPA in general) and am struggling with
> some query syntax.
> 
> I have an entity A that has a OneToMany relationship with entity B (using
> a list).
> B has an integer field 'x' that should be used for ordering the OneToMany
> relationship.
> 
> In my application I use a ReadAllQuery to select a bunch of A entities
> similar to the following:
> 
> ExpressionBuilder builder = new ExpressionBuilder();
> ReadAllQuery query = new ReadAllQuery(A.class);
> 
> Expression exp =
> builder.anyOf("someOtherOneToManyField").get("name").equal("someValue");
> 
> query.useScrollableCursor(pageSize);
> ScrollableCursor c = (ScrollableCursor) session.executeQuery(query);
> 
> However the List of B entities in the returned A entities are not sorted.
> I have played around with builder.addOrdering(Expression exp) but cannot
> figure out the proper code. No matter what I have tried it will not order
> the List of Bs, but only changes the ordering of the returned As.
> 
> Any help is appreciated thanks!
> 
> Edit: Sorry posted in the wrong format
> 


-----
---
http://wiki.eclipse.org/User:James.sutherland.oracle.com James Sutherland 
http://www.eclipse.org/eclipselink/
 EclipseLink ,  http://www.oracle.com/technology/products/ias/toplink/
TopLink 
Wiki:  http://wiki.eclipse.org/EclipseLink EclipseLink , 
http://wiki.oracle.com/page/TopLink TopLink 
Forums:  http://forums.oracle.com/forums/forum.jspa?forumID=48 TopLink , 
http://www.nabble.com/EclipseLink-f26430.html EclipseLink 
Book:  http://en.wikibooks.org/wiki/Java_Persistence Java Persistence 
-- 
View this message in context: http://www.nabble.com/Sort-Ordering-of-OneToMany-relationship-tp20874548p20896078.html
Sent from the EclipseLink - Users mailing list archive at Nabble.com.



Back to the top