0

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

Community
  • 1
  • 1
Kawu
  • 13,647
  • 34
  • 123
  • 195

2 Answers2

1

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

DataNucleus
  • 15,497
  • 3
  • 32
  • 37
  • Hmmm, barely better what I already know. So, does that effectively mean, since the order column is always in another table, that the order column must not be part of a foreign key, which would be mapped in the entity declaring the relationship field? Does that mean it is okay to have such a column as PK but not as FK in the other table? – Kawu Apr 07 '12 at 17:39
  • 2
    Such a column is not part of the entity state. So it's not mapped as anything in the entity (PK, regular field, FK or whatever). It must not be mapped. End of story. – JB Nizet Apr 08 '12 at 08:49
  • @Kawu, I see nothing difficult to understand in that statement. There is no field in the Entity. Obviously you can get at the position in the List (so the order) from accessing the List field in the owner. That's all there is. Clear as day – DataNucleus Apr 08 '12 at 17:12
1

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

Bridge
  • 29,818
  • 9
  • 60
  • 82
John Velandia
  • 129
  • 1
  • 4