我尝试创建一个ManytoMany关系anotation,其中db已经修复了结构,
A类如下
@Entity
@Table(name = "A")
public class A
@Id
@Column(name="A_ID")
private Long a_id;
....//some other attributes
@ManyToMany
@JoinTable(name="A_B",
joinColumns=@JoinColumn(name="A_ID"),
inverseJoinColumns=@JoinColumn(name="B_ID")
)
@OrderColumn(name="SORT_ORDER")
@LazyCollection(value=LazyCollectionOption.FALSE)
private List<B> bList = new ArrayList<B>();
public List<B> getBList () {
return bList ;
}
public void setBList (List<B> bList ) {
this.bList = bList ;
}
B类如下:
@Entity
@Table(name = "B")
public class B{
@Id
@Column(name="B_ID")
private Long b_id;
....//some other attributes
}
manyToMany表类A_B已经构建
A_ID B_ID SORT_ORDER
a1 b1 0
a1 b1 1
a1 b2 2
a1 b1 3
a2 b2 0
a2 b3 1
a2 b1 2
a2 b2 3
a2 b3 4
// where a_id, b_id and sort_order are composite key
如何制作注释以实现以下目标
在A类中,获取具有排序顺序的B列表
保存A类,同时保留A_B类
谢谢