在Hibernate中为连接表创建OrderTolumn for OneToMany列表映射

时间:2014-09-10 14:49:05

标签: java hibernate list jpa many-to-one

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

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

很明显,对于quadrats,没有订单,所以我使用set!

{{1}}

1 个答案:

答案 0 :(得分:1)

如果我使用属性访问,尽管方法访问,它仍然有效!像这样:

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

但是我想知道为什么它不能用于方法访问,这会迫使我在我的项目中使用重型重构器! :(