JPA: is @PrimaryKeyJoinColumn(…) the same as @Join

2019-03-15 12:14发布

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条回答
太酷不给撩
2楼-- · 2019-03-15 12:43

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

from the WikiBooks Java Persistence pages

查看更多
登录 后发表回答