我的数据库架构有以下POJO。
@Entity
@Table(name = "Quotes")
public class QuoteRequest
{
public QuoteRequest(){}
@Id
@Column(name = "quote_request_id")
@GeneratedValue(strategy = GenerationType.IDENTITY)
private long QuoteRequestId;
@OneToMany(mappedBy = "quoteRequest", cascade = CascadeType.ALL)
@OrderColumn(name = "accidents_id")
private Accidents[] accidents;
// Getters and setters
}
@Entity
@Table(name = "Accidents")
public class Accidents
{
public Accidents()
{
}
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "accidents_id")
private long AccidentId;
@Column(name = "amount", nullable = false)
private Float amount;
@ManyToOne(optional = false, cascade = CascadeType.ALL)
@JoinColumn(name = "quote_request_id", nullable = false)
private QuoteRequest quoteRequest;
// Getters and setters
}
因为我使用数组存储Accidents[]
Hibernate要求我添加@OrderColumn
。添加此选项会导致在插入后生成更新,从而将accidents_id
归零。我发现的唯一方法是将Accidents []更改为Set。
如何将Accidentsas保留为数组,并且在插入后没有Hibernate强制执行第二次更新?