简体   繁体   English

在Hibernate中的联接表上为OneToMany列表映射创建OrderColumn

[英]Creating OrderColumn for OneToMany list mapping on a join table in Hibernate

I have a productJob table and a quadrat table. 我有一个productJob表和一个quadrat表。 Every quadrat can be installed on many productJob and every productJob can have between 1 and 4 quadrats of the same or different kinds! 每个样方可以在很多安装productJobproductJob可以有1到4 quadrats相同或不同种类的! I'm interested to keep the order of quadrat installation on the product jobs. 我有兴趣在产品作业中保持Quadrat安装的顺序。 For example first, second, third or forth place! 例如第一,第二,第三或第四名! But the following mapping doesn't create the order column on the JoinTable telai_quadrati . 但是以下映射不会在JoinTable telai_quadrati上创建订单列。 What is the problem of my mapping? 我的映射有什么问题? The orderColumn isn't created in anyway! 无论如何都不会创建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}

And it is clear that for the quadrats there exists no order so I use set! 很明显,对于四边形,不存在任何顺序,因此我使用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;

It works if I use property access inspite of method access! 如果我使用属性访问而不管方法访问,它都可以工作! Like this: 像这样:

@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;

But I wonder why it doesn't work with method access that forces me a heavy refactor in my project! 但是我想知道为什么它不能与方法访问一起使用,这迫使我在项目中进行大量重构! :( :(

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM