Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » @OrderBy problem
@OrderBy problem [message #816907] Fri, 09 March 2012 12:11 Go to next message
Pavel Zelenka is currently offline Pavel Zelenka
Messages: 61
Registered: July 2009
Member
Hi,

I would appreciate any help with this problem:

Let's assume I have three entities: Order, Item and Type (one order can contain number of items. Every item holds a Type reference)
I'd like the itemList collection to be sorted by "type.code". But the @OrderBy("type.code") annotation allways throw QueryException : Invalid query key [code] in expression

Can anybody help?

Thanks


@Entity
public class Order
@Id
@Column(name = "order_id")
private Integer orderId;
@Column(name = "order_date")
@Temporal(TemporalType.DATE)
private Date orderDate
@OneToMany(mappedBy = "order", cascade = CascadeType.ALL)
@OrderBy("type.code")
private List<Item> itemList
....

@Entity
public class Type
@Id
@Column(name = "type_id")
private Integer typeId;
@Column(name = "type_code")
private Integer code
....

@Entity
public class Item
@Id
@Column(name = "item_id")
private Integer itemId;
@Column(name="item_text")
private String itemText;
@Column(name="item_value")
private Integer itemValue;
@ManyToOne(cascade = CascadeType.ALL)
@JoinColumn(name = "order_id", referencedColumnName = "order_id")
private Order order
@ManyToOne(cascade = CascadeType.ALL)
@JoinColumn(name = "type_id", referencedColumnName = "type_id")
private Type type
Re: @OrderBy problem [message #817068 is a reply to message #816907] Fri, 09 March 2012 15:44 Go to previous messageGo to next message
Chris Delahunt is currently offline Chris Delahunt
Messages: 1023
Registered: July 2009
Senior Member
The specification states that "A property or field name specified as an orderby_item must correspond to a basic persistent property
or field of the associated class or embedded class within it", so you cannot use type.code since it does not represent a property in Item.

Please file a feature request if you wish to have this added to EclipseLink as an extension to JPA.
Re: @OrderBy problem [message #818925 is a reply to message #817068] Mon, 12 March 2012 09:35 Go to previous messageGo to next message
Pavel Zelenka is currently offline Pavel Zelenka
Messages: 61
Registered: July 2009
Member
Is there a possibility to achieve this sorting via native query?
Re: @OrderBy problem [message #825186 is a reply to message #818925] Tue, 20 March 2012 15:25 Go to previous message
James Sutherland is currently offline James Sutherland
Messages: 1939
Registered: July 2009
Location: Ottawa, Canada
Senior Member

You can use a DescriptorCustomizer to customize the mapping to add an Expression for the ordering.


James : Wiki : Book : Blog : Twitter
Previous Topic:Shared cache returning same object (identity) to different sessions?
Next Topic:Criteria Query Expression isNull() not working
Goto Forum:
  


Current Time: Sun Sep 21 22:11:22 GMT 2014

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

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