JPA manytomany在使用@JoinTable时保持列表顺序

时间:2021-11-03 22:44:37

I am using a class to hold a list of persisted objects, and the order of those objects really matter to me.

我正在使用一个类来保存持久化对象的列表,这些对象的顺序对我来说真的很重要。

The class looks like this:

这个类看起来像这样:

public class Class implements Serializable {

private static final long serialVersionUID = -8772078256979276783L;

@ManyToMany(cascade={CascadeType.MERGE,CascadeType.PERSIST,CascadeType.DETACH,CascadeType.REFRESH})
@JoinTable(name = "join_table",
        joinColumns = {
        @JoinColumn(name="joinColumn") 
},
inverseJoinColumns = {
        @JoinColumn(name="inverseJoinColumn")
}
)
private List<AbstractVariant> variablesList;
}

Is there a way to add to that JoinTable an index to specify the position on the list, therefore,keeping the order safe?

有没有办法在JoinTable中添加一个索引来指定列表中的位置,从而保持订单安全?

1 个解决方案

#1


8  

That's the goal of the @OrderColumn annotation.

这是@OrderColumn注释的目标。

#1


8  

That's the goal of the @OrderColumn annotation.

这是@OrderColumn注释的目标。