JPA: @OrderColumn and visible state of an entity?

2019-09-09 11:42发布

问题:

This is a followup question to:

Is @ManyToMany(mappedBy = ... ) + @OrderColumn supported by the JPA?

I'm referring to the @OrderColumn Java docs:

http://docs.oracle.com/javaee/6/api/javax/persistence/OrderColumn.html

The text there is the same as what the JPA 2 spec writes in section 11.1.39 OrderColumn Annotation.

What does the part "the order column is not visible as part of the state of the entity" mean exactly? There's a lot of room for interpretation on that.

Does that mean the order column must not be part of any FKs and/or PKs defined? Or only not in FKs (PK allowed)? What does the state of an entity comprise? AFAIK the JPA spec doesn't define that.

Thanks

回答1:

The order column is not a field in the Entity class(es), so it isn't visible (as such).



回答2:

OPENJPA. Please look at this code, it is the best way to understand

//This is in the parent table
@OneToMany(cascade = CascadeType.ALL, mappedBy = "parentTable", fetch = FetchType.EAGER)
    @OrderColumn
    private ArrayList<child_class_type> childTable = new ArrayList<child_class_type>();

//This is in the child table
@ManyToOne(fetch = FetchType.EAGER, optional = false)
    private parentTableClass parentTable;

This will get an ordered list(child table). :)

John V, Col