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
OGM-1198 Mapping error with multiple associations on the same entity #786
Conversation
} | ||
} | ||
} | ||
|
||
return null; | ||
} | ||
|
||
private static boolean isEmpty(String mappedByProperty) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe use StringHelper
.
if ( isCollectionMatching( mainSideJoinable, inverseCollectionPersister ) ) { | ||
return inverseCollectionPersister.getAssociationKeyMetadata(); | ||
String mappedByProperty = inverseCollectionPersister.getMappedByProperty(); | ||
if ( isEmpty( mappedByProperty ) ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You prefer having a if / else if instead of a or in the first if?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thinking a bit more about it, if there is no mappedBy
, can't we consider it's not the inverse relationship? I'm surprised we returned something in this case.
@DavideD I added a few comments, the important one being about the case when we don't have a I think this one is bad enough we should consider backporting it to 5.0.x and make a release. WDYT? |
d10a163
to
6f9a66a
Compare
This fix make sure that when looking for the AssociationKeyMetadata, we consider the mappedBy value on the non-owning side of the association. Failing to do that causes some errors when there are multiple associations to the same entity
6f9a66a
to
3fd1d66
Compare
I've updated the PR following your remarks.
Good catch, I've tried to return null in that case and everything seems to work after I've updated a test. |
@DavideD well, it was a good catch but, in fact, I didn't realize the method was working when we passed an inverse side relationship to it. The javadoc is very clear it's not supposed to and it's only used to manage the navigational information of the inverse side so I think we're safe and it's better to be strict about this. I was more thinking about the user declaring a relation that could match but isn't declared as an inverse relationship with a |
Rebased and merged! |
https://hibernate.atlassian.net/browse/OGM-1198
Check the link on stack Overflow for an example: http://stackoverflow.com/questions/40288481/persist-a-tree-with-hibernate-ogm-and-mongodb-the-collections-that-represent-th