允许单个id有多个记录的首选方式



我有如下的弹簧引导应用程序

@Entity
@Table( name="request_details")
@Data
public class RequestDetails{
@Id
@Column(name="data_id")
long id
String status;
@Lob
byte[] attachment;
}

以前的要求是每个请求只允许附件,现在的要求是更改为单个请求可以有多个附件,现在我无法为单个请求存储多个附件——因为所有附件都有相同的data_id,修改这种方式的最佳方法是什么?

我应该使用isNew方法吗?我应该通过将data_id与请求隔离来更改实现吗?(考虑到我也需要更新数据库模式,这将是一个非常大的变化(

一种方法是第二列,它将不同的记录分组,如(伪代码(

table request_details
ID (primary key),
attachment_nbr
... some other atributes
attachment (LOB)
unique constraint on ID, attachment_nbr

分组属性attachment_nbr必须以任何方式计算或从序列号生成器中获得。

更好的方法是使用两个独立的表,如(伪代码(

table request
ID (primary key)
... some other attributes
table attachments
ID primary key
... some other atributes
attachment (LOB)
request_id (foreign_key request.ID)

最新更新