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

6.1.12.RELEASE / 7.0.1.RELEASE BUG - Unable to save changes from custom GORM EventListener #1265

Closed
codeconsole opened this issue Aug 28, 2019 · 1 comment · Fixed by grails/gorm-hibernate5#173

Comments

@codeconsole
Copy link
Contributor

codeconsole commented Aug 28, 2019

The following worked in Grails 3.3.9 and below:

In Grails 3.3.10 and 4.0.0, the listener code is executed, but the changes performed on the entityObject are no longer persisted.

Assuming a class Example with a field prop, we want to create a Listener that will automatically set prop on an Insert event.

class Example {

	Date created = new Date()
	String prop

    static constraints = {
    	created()
    	prop nullable: true
    }
}
@CompileStatic
class ExampleListener extends AbstractPersistenceEventListener {

    ExampleListener(final Datastore datastore) {
        super(datastore)
    }

    @Override
    @CompileStatic(TypeCheckingMode.SKIP) 
    protected void onPersistenceEvent(AbstractPersistenceEvent event) {
        def o = event.entityObject
        o.prop = 'autoset'
        println "Autoset"
    }

    @Override
    boolean supportsEventType(Class<? extends ApplicationEvent> eventType) {
        eventType == PreUpdateEvent || eventType == PreInsertEvent
    }
}

The following code can be demonstrated here:
https://github.com/codeconsole/listenerbug

git clone https://github.com/codeconsole/listenerbug
# set version to Grails 4.0.0
grails run-app

To demonstrate the bug on Grails 3.x

# set version to Grails 3.3.10 and checkout the 3.3.10 tag
git checkout 3.3.10
grails run-app

Rolling back gormVersion=6.1.11.RELEASE in gradle.properties on Grails 3.3.10 fixes the issue.
this can be demonstrated by switching to tag working using grails 3.3.10

# set version to Grails 3.3.10 and checkout the 3.3.10 tag
git checkout working
grails run-app

https://github.com/grails/grails-data-mapping/compare/v6.1.11..v6.1.12

@puneetbehl puneetbehl self-assigned this Jan 23, 2020
@puneetbehl puneetbehl changed the title 6.1.12.RELEASE / 7.0.1.RELEASE BUG - Something Seriously Broke - Example Provided 6.1.12.RELEASE / 7.0.1.RELEASE BUG - Unable to save changes from custom GORM EventListener Jan 27, 2020
@puneetbehl
Copy link
Contributor

I believe this is caused by issue #1064 because we removed activateDirtyChecking method call from ClosureEventTriggeringInterceptor::onSaveOrUpdate.

puneetbehl added a commit that referenced this issue Jan 31, 2020
puneetbehl added a commit that referenced this issue Jan 31, 2020
Fixed typo with the variable
puneetbehl added a commit to grails/gorm-hibernate5 that referenced this issue Jan 31, 2020
puneetbehl added a commit to grails/gorm-hibernate5 that referenced this issue Jan 31, 2020
graemerocher pushed a commit to grails/gorm-hibernate5 that referenced this issue Feb 4, 2020
* grails/grails-data-mapping#1265 Hibernate5 test to update from the AbstractPersistentEventListener

* Revert "improve dirty checking of new entity instances" in favour of grails/grails-data-mapping#1265

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

Successfully merging a pull request may close this issue.

2 participants