我有一个productJob表和一个quadrat表。每个quadrat可以安装在许多productJob上,每个productJob可以具有1到4个相同或不同种类的quadrats!我有兴趣在产品作业中保持Quadrat安装的顺序。例如第一,第二,第三或第四名!但是以下映射不会在JoinTable telai_quadrati上创建订单列。我的映射有什么问题?无论如何都不会创建orderColumn!

@Entity
@Table(name = "telai")
public class ProductJob implements IProductJob, IProductJobProcessing{
     @Embedded private QuadratGroup quadrateGroup = new QuadratGroup();
}

@Embeddable
public class QuadratGroup implements Serializable{
     @OneToMany(targetEntity = Quadrat.class, cascade = CascadeType.ALL)
     @JoinTable(
        name = "telai_quadrati",
        joinColumns = {@JoinColumn(name = "dbId", table = "telai")},
        inverseJoinColumns = {@JoinColumn(name = "id", table = "quadrati")})
     //@OrderColumn(name = "order")
     @IndexColumn(name = "order")
     public List<Quadrat> getQuadratList(){ //return an ordered list of the quadrats with at most 4 elements}


很明显,对于四边形,不存在任何顺序,因此我使用set!

@Entity
@Table(name = "quadrati")
public class Quadrat implements IQuadrat, Cloneable, Serializable{
    @ManyToMany
    @JoinTable(
        name = "telai_quadrati",
        joinColumns = @JoinColumn(name = "id", table = "quadrati"),
        inverseJoinColumns = @JoinColumn(name = "dbId", table = "telai"))
    private Set<ProductJob> productJobs;

最佳答案

如果我使用属性访问而不管方法访问,它都可以工作!像这样:

@OneToMany(targetEntity = Quadrat.class, cascade = CascadeType.ALL)
//@MapKeyJoinColumn(name="indice" , table = "telai_quadrati")
@JoinTable(
        name = "telai_quadrati",
        joinColumns = {@JoinColumn(name = "telaio_id", table = "telai")},
        inverseJoinColumns = {@JoinColumn(name = "quadrato_id", table = "quadrati")})
@OrderColumn(name = "indice")
private List<Quadrat> quadratList;


但是我想知道为什么它不能与方法访问一起使用,这迫使我在项目中进行大量重构! :(

07-26 08:23