@OrderColumn annotation in Hibernate 3.5

前端 未结 3 1535
醉梦人生
醉梦人生 2020-11-27 04:10

I\'m trying to use the @OrderColumn annotation with Hibernate 3.5

@OneToMany(mappedBy = \"parent\",fetch=FetchType.EAGER, cascade=CascadeType.AL         


        
3条回答
  •  有刺的猬
    2020-11-27 04:29

    Do something like this:

    @Entity
    class Parent {
    
        @OneToMany
        @OrderColumn(name = "pos")
        List children;
    }
    
    @Entity
    class Child {
    
        @ManyToOne
        Parent parent;
        @Column(name = "pos")
        Integer index;
    
        @PrePersist
        @PreUpdate
        private void prepareIndex() {
            if (parent != null) {
                index = parent.children.indexOf(this);
            }
        }
    }
    

提交回复
热议问题