简体   繁体   中英

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.

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM