为什么我可以插入主题表中不存在的FK数据库(帖子表)?
@Entity
class Post(@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
val id: Long = 0,
@Column(nullable = false)
val message: String = "",
val tpc_id: Long = 0
)
@Entity
class Topic (@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
val id: Long = 0,
@Column(nullable = false)
val title: String = "",
val description: String = "",
@OneToMany(fetch = FetchType.LAZY)
@JoinColumn(name = "tpc_id", nullable = false, insertable = false, updatable = false)
val posts: List<Post>
)
当我说带有ID的主题时:1、2、3为什么在帖子中我可以添加引用主题ID(即10)的帖子?