Java JPA:@PrimaryKeyJoinColumn(...) 和 @JoinColumn(..., insertable = ?, updatable = ?) 一样吗?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4205628/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-14 14:33:13  来源:igfitidea点击:

JPA: is @PrimaryKeyJoinColumn(...) the same as @JoinColumn(..., insertable = ?, updatable = ?)?

javajpamappingprimary-keyjpa-2.0

提问by Kawu

Can you derive from the JPA spec, if @PrimaryKeyJoinColumn(...), which doesn't have the insertable and updatable parameters, is the same as

您能否从 JPA 规范中推导出@PrimaryKeyJoinColumn(...)没有可插入和可更新参数的if与

@JoinColumn(..., insertable = false, updatable = false)

or

或者

@JoinColumn(..., insertable = true, updatable = true)

@JoinColumn(..., 可插入 = 真, 可更新 = 真)

when used on regular (non-inheritance) associations? Should they be interchangable? What are the insertable and updatable properties set to? Are they set to anything at all? Note, I'm only targeting the read-only attribute that both (seem to) implement...

何时用于常规(非继承)关联?它们应该可以互换吗?可插入和可更新属性设置为什么?他们有没有设置任何东西?请注意,我只针对两者(似乎)实现的只读属性......

I'm getting rather inconsistent mapping exception with EclipseLink and Hibernate...

我在使用 EclipseLink 和 Hibernate 时遇到了相当不一致的映射异常...

Here's the @PrimaryKeyJoinColumnJavaEE 5 + 6 Javadoc:

这是@PrimaryKeyJoinColumnJavaEE 5 + 6 Javadoc:

PrimaryKeyJoinColumn (JavaEE 5)
PrimaryKeyJoinColumn (JavaEE 6)

PrimaryKeyJoinColumn (JavaEE 5)
PrimaryKeyJoinColumn (JavaEE 6)

Quote:

引用:

... and it may be used in a OneToOne mapping in which the primary key of the referencing entity is used as a foreign key to the referenced entity.

...并且它可以用在 OneToOne 映射中,其中引用实体的主键用作被引用实体的外键。

采纳答案by James

Yes, the two are equivalent.

是的,两者是等价的。

Note in JPA 2.0 you can also add an @Idto a @OneToOnemapping and avoid having the duplicate basic id attribute altogether.

请注意,在 JPA 2.0 中,您还可以@Id@OneToOne映射添加 ,并完全避免具有重复的基本 id 属性。

See

from the WikiBooks Java Persistencepages

来自WikiBooks Java Persistence页面