devmao
devmao

Reputation: 680

In JPA can I access the field created by the @OrderColumn into the collected entity?

My sample code:

 public class A {

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

 public class B {

  @Column(name = "ORDER")
  private Integer order; // I need this field because I want 
                         // to use the ordering field in my query.
  ...
 }

With this code EclipseLink try to create the "ORDER" column 2 times throwing an exception and don't create the B table.

Thanks.

Upvotes: 7

Views: 1094

Answers (2)

Piotr Gwiazda
Piotr Gwiazda

Reputation: 12222

Use @OrderBy instead of @OrderColumn. Look at reference http://docs.oracle.com/javaee/6/api/javax/persistence/OrderColumn.html

Upvotes: 1

James
James

Reputation: 18389

Please log a bug for this issue on EclipseLink.

You should not need the column just for querying, you can use the JPQL INDEX(bList) to query the order column.

In EclipseLink you can also use a DescriptorCustomizer to define a QueryKey for any column to allow querying on it.

Upvotes: 2

Related Questions