clarify usage of @OrderColumn and @MapKeyColumn#794
clarify usage of @OrderColumn and @MapKeyColumn#794gavinking merged 4 commits intojakartaee:mainfrom
Conversation
this is a big source of confusion
76a025e to
cfbcdab
Compare
|
Damn, the TCK actually has tests which test the use of these annotations on unowned collections, where the order or key column doesn't exist at all in the other entity, creating a requirement for "partially owned" collections. I really think this is an incredibly bad feature, typically resulting in inefficient SQL, and that we should strongly consider deprecating it. Thoughts, everyone? |
|
I mean, the spec also says:
and:
This notion of a "partially owned" relationship just doesn't exist in the text of the specification, as far as I can tell. It's a pure invention of the TCK. |
|
The |
It only makes sense if the child entity has a field holding the value of the map key. In which case, you should use |
|
It seems to me that with a |
I mean, OK, in principle yes ... but that "map key column" would then wind up being a unique key of the join table. I doubt any JPA implementation handles this mapping elegantly (Hibernate doesn't). If some JPA implementation wants to support such mapping, that's fine, it can. But I don't think the spec should require support for that. (I'm assuming you mean that it's a bidirectional many-to-many with a |
Sure, it would form a unique constraint along with the foreign key columns pointing to the owning side. If Hibernate doesn't behave correctly here, that would be a bug that we should simply fix IMO.
Right, so maybe change the language to say that support for this kind of mapping is non-portable or something like that.
Obviously |
That is possible, and completely normal. What is extremely debatable is whether you should be able to have things like a |
njr-11
left a comment
There was a problem hiding this comment.
Added a few minor suggestions for grammar corrections and copy/paste mistakes. Otherwise, approving in advance.
Co-authored-by: Nathan Rauh <nathan.rauh@us.ibm.com>
|
Thanks @njr-11, I applied all your suggestions. Not going to merge this for M1, because I still want to get @sebersole's feedback on it, especially since @beikov was a bit skeptical of this one. |
Shocking |
|
How about we carve out an exception in the clarification for the many-to-many case? |
Hibernate actually does allow that IIRC, but it uses two SQL statements to set up the association. |
|
This is not so much about what is possible, but about what the spec requires. |
Hence "fix" in quotes. "Improve" if you prefer ;) |
|
Just for your information, there seem to be people out there that really use |
0562f6e to
091baf3
Compare
but that this is not portable
091baf3 to
df4085e
Compare
|
I have weakened the language slightly, so that it's clear that an implementation might allow these annotations on the unowned side, and what we're saying is just that it's unportable. |
|
I'm going to pull the trigger on this one, because I believe it correctly states the original intent of these annotations. |
And because we have not defined anywhere in the spec how a "partially owned" collection mapping is supposed to behave. (And such a definition is completely nontrivial.) |
I've realized that there's huge confusion here, because the Javadoc for these annotations fails to mention an important thing.