Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JPA manytomany keep list order while using @JoinTable

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?

like image 646
Josep Rodríguez López Avatar asked Nov 02 '11 15:11

Josep Rodríguez López


1 Answers

That's the goal of the @OrderColumn annotation.

like image 141
JB Nizet Avatar answered Oct 21 '22 03:10

JB Nizet