gpt4 book ai didi

Hibernate Annotation 连接表问题

转载 作者:行者123 更新时间:2023-12-05 00:08:54 26 4
gpt4 key购买 nike

使用 hibernate 注释进行连接表时,如何添加一个不是连接列的额外列,例如,已婚为弱实体?像一个额外的列?

@ManyToMany(targetEntity=some.class,
cascade ={CascadeType.PERSIST, CascadeType.MERGE}, fetch=FetchType.EAGER)
@JoinTable(name = "RELATION", joinColumns ={
@JoinColumn(name = "HID", unique = true)
}, inverseJoinColumns = {
@JoinColumn(name = "FID")
})
Set<PERSON> PEOPLE = new HashSet<PERSON>();

最佳答案

第三列在技术上使该表成为实体,而不是“可连接的”。所以表本身需要是一个实体。从 SQL 的角度考虑。当连接表不仅仅是将两个其他表连接在一起所需的信息时,它是否只是一个连接表?

同样仅供引用,此场景在“Java Persistence (JPA) with Hibernate”的第 7 章中有介绍:

You can use two common strategies to map such a structure to Java classes. The first strategy requires an intermediate entity class for the join table and is mapped with one-to-many associations. The second strategy utilizes a collection of components, with a value-type class for the join table.

关于Hibernate Annotation 连接表问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1019721/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com