-
Notifications
You must be signed in to change notification settings - Fork 73
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support OneToOne mapping with JoinTable #196
Comments
As the docs ( http://www.datanucleus.org/products/accessplatform_5_0/jpa/mapping.html#one_one_relations ) say clearly enough, 1-1 with join table is not supported and minority interest use-case. [Even the EclipseLink/Wikibooks docs says that is not part of the JPA spec]. PS, this relates solely to the datanucleus-rdbms plugin so not really the place for it. |
Must have missed that then. Thanks for the info. |
Marking as wont-fix since the work would have to be on the RDBMS plugin only (nothing in core cares about join tables and the like), and opened datanucleus/datanucleus-rdbms#180, so use that as reference. Not likely to attract my attention in some time ;-) |
I've never had a need to have a one to one implemented as a join rather than as a bidirectional set of FKs. I imagine it would be slower than a simple bidirectional set FKs because it needs to involve a third table. A joined one to one is an interesting use case so I'm wondering if there is an advantage to this approach that I've missed. |
Consider this simple entity model
When creating a
EntityManagerFactory
with the property "javax.persistence.schema-generation.database.action" set to "create" it fails. The error is a syntax error in the generated DDL statementALTER TABLE DOCUMENT ADD CONSTRAINT DOCUMENT_U1 UNIQUE ()
.There are multiple problems here that I found. Apparently a
@OneToOne
with a@JoinTable
is not really supported yet? Anyway, the problems essentially seem to be that the@JoinTable
is partly/fully ignored. This is because a join table with a different name i.e. "document_documentinfo" and different column names is generated instead.There should be 2 unique constraints generated for the join table. One for the "document_id" and another for the "document_info_id" instead of an empty constraint for the "document" table.
The ignoring of the
@JoinTable
also suggests that a simple@OneToOne
without a@JoinColumn
annotation would fail too, although in that case a default join column name should be chosen.The issues are DBMS independent and produce consistently bad DDL on H2, MySQL and PostgreSQL.
The text was updated successfully, but these errors were encountered: