Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
在这个例子中
我了解该mappedBy属性在做什么。它告诉 JPA 外键存在于用户表中。但是db中的外键是一个字段,但是这里他们指定了一个完整的对象
mappedBy
计费信息
作为外键。JPA 如何知道 BillingInfo 对象中的哪个字段用作外键?
mappedBy = "billingInfo"没有说外键在哪里。它告诉 Hibernate 带注释的字段 ( user) 构成双向关联的反面,并且该关联的拥有方是字段User.billingInfo。
mappedBy = "billingInfo"
user
User.billingInfo
因此,Hibernate 会查看如何User.billingInfo映射以了解必须如何映射此双向关联。在这种情况下,唯一的注释User.billingInfo是@OneToOne。由于这并没有说明关联是如何映射的,因此将应用 JPS 规范中指定的默认值,并且 IIRC"billingInfo_id"将使用名为的连接列。
@OneToOne
"billingInfo_id"