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

社会主义新天地 提交于 2019-12-03 13:05:53

问题


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

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

or

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

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...

Here's the @PrimaryKeyJoinColumn JavaEE 5 + 6 Javadoc:

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.


回答1:


Yes, the two are equivalent.

Note in JPA 2.0 you can also add an @Id to a @OneToOne mapping and avoid having the duplicate basic id attribute altogether.

See

  • Identity and Sequencing > Primary Keys through OneToOne and ManyToOne Relationships and
  • OneToOne > Target Foreign Keys, Primary Key Join Columns, Cascade Primary Keys

from the WikiBooks Java Persistence pages



来源:https://stackoverflow.com/questions/4205628/jpa-is-primarykeyjoincolumn-the-same-as-joincolumn-insertable

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!