When a new relationship is created the columns of the RowKey are saved as properties of the relationship. This properties are usually redundant because they are already in the nodes connected by the relationship. We should only create the properties related to the association.
Note that if we don't have the property on the relationship is not going to be possible to rebuild the RowKey when GrdiDialect#getAssociation(...) is called with the current available information in the AssociationKey and AssociationContext.
Let's take as an example BidirectionalManyToManyTest with AccountOwner and BankAccount, this is the information I have when Neo4jDialect#createTupleAssociation(...): is called:
EntityKey{table='AccountOwner', columnNames=[id], columnValues=[...]} AssociationKey{table='AccountOwner_BankAccount', columnNames=[owners_id], columnValues=[...]} RowKey{table='AccountOwner_BankAccount', columnNames=[owners_id, bankAccounts_id], columnValues=[...]}
What I want to obtain is the creation of a relationship like the following (I've omitted the type of the relationship and the properties): (AccountOwner) - [r] - (BankAccount)
In this case the associationKey owner is AccountOwner and I can obtain the key to identify the corresponding node from AssociationKey#entityKey, what I'm missing is the metadata information to find the BankAccount node the relationship has to be connected. With the current data I can extract the fact that the bankAccounts_id contains the id of target entity (BankAccount) but I don't know the name of the entity and which column contains the id.
To solve this problem I've added the following information in the AssociationContext: AssociationContext#targetEntityKeyMetadata and AssociationContext#targetAssociationKeyMetada In the same example this values would be:
AssociationContext#targetEntityKeyMetadata = EntityKeyMetadata{table='BankAccount', columnNames=[id]} AssociationContext#targetAssociationKeyMetada = AssociationKeyMetadata{table='AccountOwner_BankAccount', columnNames=[bankAccounts_id]}
With this additional fields I can now find the BankAccount node and create the relationship.
Note that removing the temp nodes is related to this issue because I cannot remove them without having this additional information.
I've also added the field AssociationKey#targetKey but writing this reply I've noticed that I can remove it.
|