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

Delete methods applied to objects, but Hibernate filter not executing #13

Open
mamsterla opened this issue Aug 22, 2014 · 1 comment
Open

Comments

@mamsterla
Copy link

I have a large project in which I would like to apply logical deletes (due to financial integrity issues). I have added the @LogicalDelete annotation to the classes and collections that apply. I can see that the domain objects are altered in the database to include the deleted property. When I call delete() I can see the value in the database change to 1 indicating a successful logical delete.
However it appears that the Hibernate filter is not being used at all. I have turned on SQL logging and I do not see the deleted = 0 appended to any of the queries on my domain classes. I am using criteria queries in controller classes or service classes typically. I have added debugging and I can see that the logicalDeleteHibernateFilter is defined and enabled. I am at a loss to see why the Hibernate filter is not being applied when all else seems to be working.

Env. is Grails 2.3.8
Database is MySQL5

@mamsterla
Copy link
Author

I created a trivial project with a single Domain class and a single Controller with two actions. It shows that the logical delete occurs, but the subsequent list shows the deleted object.

Here is the Domain class - Squid.groovy:

package logicaldeleteproj

import com.nanlabs.grails.plugin.logicaldelete.LogicalDelete

@LogicalDelete
class Squid {

Integer squidCount

static constraints = {
}

}

Here is the Controller class: SquidController.groovy:

package logicaldeleteproj

import grails.converters.JSON

class SquidController {

def index() {
    for(int i = 0; i < 10; i++ ) {
        new Squid(squidCount: i).save()
    }
    def output = [squid: Squid.list(), squidCount: Squid.count()]
    render output as JSON
}

def delete() {
    if (params.del) {
        def deadSquid = Squid.findBySquidCount(params.int("del"))
        deadSquid.delete()
    }
    def output = [squid: Squid.list(), squidCount: Squid.count()]
    render output as JSON
}

}

Just create a fresh project with the standard Grails 2.3.8 grails app-create
Then add:
compile ":logical-delete:0.1"
to the BuildConfig.groovy
Then run and go to the page:
http://localhost:8080/LogicalDeleteProj/Squid
Followed by
http://localhost:8080/LogicalDeleteProj/Squid/delete?del=3

You will see from the dump that the Squid object is present in the Squid.list even though the deleted field is present and set to true.

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