JPA: @OrderColumn and visible state of an entity?

萝らか妹 提交于 2019-12-14 03:18:08

问题


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



来源:https://stackoverflow.com/questions/10054400/jpa-ordercolumn-and-visible-state-of-an-entity

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!