Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » OrderBy problem when traversing properties
OrderBy problem when traversing properties [message #667445] Thu, 28 April 2011 18:33 Go to next message
Ari Meyer is currently offline Ari MeyerFriend
Messages: 136
Registered: July 2009
Senior Member
Hi,

I'm using Eclipselink 2.1.3. I'm not sure if the problem I'm seeing
relates to https://bugs.eclipse.org/bugs/show_bug.cgi?id=264001 and/or
https://bugs.eclipse.org/bugs/show_bug.cgi?id=219814, or perhaps the
problem is on my side. I have a OneToMany mapping case where we want to
specify ordering like this:

@OrderBy("employee.lastName, employee.firstName")

or even just:

@OrderBy("employee.lastName")

For both cases, though, the static weaver reports:

Internal Exception: Exception [EclipseLink-7217] (Eclipse Persistence
Services - 2.1.3.v20110304-r9073):
org.eclipse.persistence.exceptions.ValidationException
Exception Description: The order by value [employee.lastName], specified
on the element [projMembers] from entity [class
mil.army.usace.p2.entity.UsaceProject], is invalid. No property or field
with that name exists on the target entity [class
mil.army.usace.p2.entity.ProjMember].
at
org.eclipse.persistence.exceptions.StaticWeaveException.exce ptionPerformWeaving(StaticWeaveException.java:138)
at
org.eclipse.persistence.tools.weaving.jpa.StaticWeave.main(S taticWeave.java:86)

However, it does accept:
@OrderBy("employee")

Here are the code sections in question (let me know if you need the full
classes):

UsaceProject:
@OneToMany(
cascade=CascadeType.ALL,
mappedBy="project",
orphanRemoval=true)
@OrderBy("employee.lastName, employee.firstName")
private List<ProjMember> projMembers;

ProjMember:
@ManyToOne(fetch=FetchType.EAGER)
@JoinColumns({
@JoinColumn(name="EMP_ID_NO", referencedColumnName="EMP_ID_NO",
insertable=false, updatable=false),
@JoinColumn(name="FOA_CODE", referencedColumnName="FOA_CODE",
insertable=false, updatable=false)
})
private Employee employee = null;

Employee:
@Column(name="EMP_LNAME")
private String lastName;

@Column(name="EMP_FNAME")
private String firstName;


Thanks in advance for the help!
Ari
Re: OrderBy problem when traversing properties [message #667454 is a reply to message #667445] Thu, 28 April 2011 20:01 Go to previous messageGo to next message
Chris Delahunt is currently offline Chris DelahuntFriend
Messages: 1389
Registered: July 2009
Senior Member
Hello,

"employee" is an attribute within ProjMember that can be used to look up fields within the table associated to ProjMember to use in the order by clause. ProjMember does not contain "employee.firstName", and the fields for the mapping do not exist within the ProjMember so it would require a join to the Employee table for odering to work.

Feel free to file an enhancement, as this could be used to indicate that a join be done to the Employee table. Such a feature would need to work around JPA specifying that orderby take only a property_or_field_name since "employee.firstName" is a path expression.

Workaround would be to not map this relationship, and instead query for ProjMembers when required with orderby used in the query.

Best Regards,
Chris
Re: OrderBy problem when traversing properties [message #667477 is a reply to message #667454] Fri, 29 April 2011 00:04 Go to previous messageGo to next message
Ari Meyer is currently offline Ari MeyerFriend
Messages: 136
Registered: July 2009
Senior Member
Thanks, Chris -- appreciate the clarification.
Ari
Re: OrderBy problem when traversing properties [message #667912 is a reply to message #667477] Mon, 02 May 2011 18:33 Go to previous messageGo to next message
James Sutherland is currently offline James SutherlandFriend
Messages: 1939
Registered: July 2009
Location: Ottawa, Canada
Senior Member

You can also set the orderBy directly on the ForeignReferenceMapping using a DescriptorCustomizer, using any valid Expression.


James : Wiki : Book : Blog : Twitter
Re: OrderBy problem when traversing properties [message #668303 is a reply to message #667912] Thu, 05 May 2011 04:34 Go to previous message
Ari Meyer is currently offline Ari MeyerFriend
Messages: 136
Registered: July 2009
Senior Member
Thanks, James.
Ari

On 5/2/2011 1:33 PM, James wrote:
> You can also set the orderBy directly on the ForeignReferenceMapping
> using a DescriptorCustomizer, using any valid Expression.
>
Previous Topic:Can't get static weaving working
Next Topic:getting PSQLException Can't infer the SQL type to use with Native Query call
Goto Forum:
  


Current Time: Fri Apr 26 20:22:09 GMT 2024

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

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

Back to the top