Skip to content
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

save() on association does not cascade in 4.x/5.x #874

Open
yvesf opened this issue Feb 17, 2017 · 0 comments
Open

save() on association does not cascade in 4.x/5.x #874

yvesf opened this issue Feb 17, 2017 · 0 comments

Comments

@yvesf
Copy link

yvesf commented Feb 17, 2017

Please see the following test for grails-datastore-gorm-test: gist SaveCascadeSpec.groovy

It contains two cases for two relation types:

  • ToOne: This one fails in gorm 4.x branch and 5.x branch. It looks like a incomplete logic in NativeEntryEntityPersister
  • OneToMany: This one succeeds in gorm 4.x, it fails in 5.x branch.

As it is shown in the test, I assume that a entity with a association where the other end belongsTo should cascade on save. This is what I understood from the 'cascade' help in the docs.

My idea to fix the ToOne is to not only check for empty id but also do the dirty check in the NativeEntryEntityPersister:

// else if (prop instanceof ToOne) { ...
if (tempId == null) {
    if (association.isOwningSide()) {
        tempId = session.persist(associatedObject);
    }
} else if (associatedObject instanceof DirtyCheckable) {
    if (((DirtyCheckable)associatedObject).hasChanged()) {
        tempId = associationPersister.persist(associatedObject);
    }
}

For the OneToMany I have currently no idea how to fix it. I just realized that in the NativeEntityPersister is only checking if the PersistentSet is dirty. This is not the case, it's the entry inside the PersistentSet that is dirty.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant