package main.foo;
import javax.persistence.*;
import java.util.List;
/**
* Created by mihaildoronin on 27/11/15.
*/
@Entity
public class Foo {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private int id;
@OneToMany(cascade = CascadeType.ALL, mappedBy = "foo")
@OrderColumn(nullable=false)
private List<Bar> bars;
private String name;
public List<Bar> getBars() {
return bars;
}
public void setBars(List<Bar> bars) {
this.bars = bars;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
package main.foo;
import org.springframework.cglib.core.GeneratorStrategy;
import javax.annotation.Generated;
import javax.persistence.*;
/**
* Created by mihaildoronin on 27/11/15.
*/
@Entity
public class Bar {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private int id;
@ManyToOne
private Foo foo;
private String name;
public Foo getFoo() {
return foo;
}
public void setFoo(Foo foo) {
this.foo = foo;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
当我试图将条形贴到条形图时,它会给我这个错误。
NULL not allowed for column \"BARS_ORDER\"; SQL statement:\ninsert into bar (id, foo_id, name) values (null, ?, ?)
如果我将OrderColumn设为可空,那么我就可以发布,但是无法获取GET / foos // bars资源,并且有关此列的内容为null。这基本上是说spring-data-rest无法处理有序的子集合。
我有什么可以做的,所以我可以得到有序的子集合吗?我的意思是我可能会在条形图中使用几个OneToOne关系进行链接列表,但这对性能非常不利,所以可能还有另一种方式吗?