Skip to main content



      Home
Home » Eclipse Projects » EclipseLink » Query field created by the @OrderColumn(JPQL accessing @OrderColumn automatically generated field)
Query field created by the @OrderColumn [message #778313] Thu, 12 January 2012 05:26 Go to next message
Eclipse UserFriend
I have an entity like this:
 public class A {

  @OneToMany
  @OrderColumn(name = "MYORDER")
  private List<B> bList;
  ...
 }

I need to fetch from database some B objects ordered by the created MYORDER column.

If I define a field in B like this:
public class B {

  @Column(name = "MYORDER")
  private Integer order;
  ...
 }

And I try to query with:

SELECT b FROM B b WHERE ... ORDER BY b.order


EclipseLink try to create the "MYORDER" column 2 times throwing an exception and doesn't create the B table.

I can't fetch A objects because I need to fetch some B objects belonging to different A objects (even no A objects)

How can I solve this?

Regards

Alessandro

[Updated on: Thu, 12 January 2012 05:37] by Moderator

Re: Query field created by the @OrderColumn [message #778357 is a reply to message #778313] Thu, 12 January 2012 10:19 Go to previous messageGo to next message
Eclipse UserFriend
By specifying the @OrderColumn(name = "MYORDER") on the OneToMany you are saying that the bList controls that field. I'm guessing that the error you get states that you have two writable fields, or is due to the field already existing.

If you are going to map the MYORDER field within the B object directly, you should be using the OrderBy on the collection instead of OrderColumn and maintain the collection order and the order field yourself.

Best Regards,
Chris
Re: Query field created by the @OrderColumn [message #778623 is a reply to message #778313] Fri, 13 January 2012 09:43 Go to previous message
Eclipse UserFriend
Hello,

If you just want the list to be returned ordered, use the @OrderBy annotation instead. OrderColumn causes the field to be controlled by the collection.

Please file a bug though, as the field should not be written twice. Instead, you should get an exception stating that the field is mapped twice (since both the collection and the basic mapping try to write to the field).

Best Regards,
Chris
Previous Topic:automatic persist without cascade, persist replacing entity
Next Topic:Query field created by the @OrderColumn
Goto Forum:
  


Current Time: Sat Jul 12 15:09:13 EDT 2025

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

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

Back to the top