Quantcast

Grails 2.0.3 with hibernate Envers

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Grails 2.0.3 with hibernate Envers

chris.zhao
This post was updated on .
Hi folks,

Anyone managed to get Hibernate Envers work with grails 2.0.3 for auditing domain classes?

I added hibernate envers dependency in my BuildConfig.groovy:
 compile ('org.hibernate:hibernate-envers:3.6.10.Final') {
                    transitive = false
        }

and I registered hibernate event listener in my resources.groovy:
auditListener(AuditEventListener)

    hibernateEventListeners(HibernateEventListeners) {
        listenerMap = ['post-insert': auditListener,
                'post-update': auditListener,
                'post-delete': auditListener,
                'pre-collection-update': auditListener,
                'pre-collection-remove': auditListener,
                'post-collection-recreate': auditListener
        ]
    }

and I added @Audited annotation in my domain class:
@Audited
class Book {

    String title
    String author

    static constraints = {
    }
}

I can see there are two tables created by envers:  BOOK_AUD and REVINFO, but after I saved some data to BOOK table, I cannot see any record in BOOK_AUD and REVINFO tabke...  Have I missed anything here?

Any hints will be appreciated!
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Grails 2.0.3 with hibernate Envers

chris.zhao
anyone?? I am surprised I am the only one having this issue..
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Grails 2.0.3 with hibernate Envers

Graeme Rocher-4
Administrator
Have you tried https://github.com/lucaslward/grails-envers-plugin

Cheers

On Fri, May 11, 2012 at 2:06 AM, chris.zhao <[hidden email]> wrote:

> anyone?? I am surprised I am the only one having this issue..
>
> --
> View this message in context: http://grails.1312388.n4.nabble.com/Grails-2-0-3-with-hibernate-Envers-tp4612685p4625068.html
> Sent from the Grails - user mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe from this list, please visit:
>
>    http://xircles.codehaus.org/manage_email
>
>



--
Graeme Rocher
Grails Project Lead
SpringSource - A Division of VMware
http://www.springsource.com

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Grails 2.0.3 with hibernate Envers

ideasculptor


On Fri, May 11, 2012 at 3:04 AM, Graeme Rocher <[hidden email]> wrote:
Have you tried https://github.com/lucaslward/grails-envers-plugin

That plugin looks quite out of date (envers is still a jboss package instead of hibernate, etc), but it certainly contains a bunch of useful ideas and code (it shows how to include the current user in the revision info etc) which should get people pointed in the right direction for using envers in a grails app. Strangely, it actually excludes the SpringSecurityRevisionListener and UserRevisionEntity when you install the plugin - that seems like a useful bit of functionality, though maybe there is some way to pull them back in other than copying their source into a different app manually?

The setup code (without the revision listener and revision entity), which should demonstrate how to set things up in your local app without the plugin, is all in  EnversGrailsPlugin.groovy

--sam

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Grails 2.0.3 with hibernate Envers

chris.zhao
This post was updated on .
Thanks for the response, because from grails 2.0.3 documentation it mentions something about audit event listener:

For example, you could register a class AuditEventListener which implements PostInsertEventListener, PostUpdateEventListener, and PostDeleteEventListener using the following in an application:

beans = {
   auditListener(AuditEventListener)

   hibernateEventListeners(HibernateEventListeners) {
      listenerMap = ['post-insert': auditListener,
                     'post-update': auditListener,
                     'post-delete': auditListener]
   }
}

So I assume it should just work, and the AuditEventListener here should be the hibernate envers one. Strangely, since  Envers is included as a Hibernate core module from 3.5 and grails 2 bundled with hibernate 3.6, but I still have to declare envers dependency from BuildConfig.groovy in order for it to be picked up. I thought maybe just something was missed or mis-configured.. anyway, will check out hibernate envers plugin see if I can get it work with grails 2

Cheers
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Grails 2.0.3 with hibernate Envers

ideasculptor


On Fri, May 11, 2012 at 6:30 PM, chris.zhao <[hidden email]> wrote:
Thanks for the response, because from grails 2.0.3 documentation it mentions
something about audit event listener:

For example, you could register a class AuditEventListener which implements
PostInsertEventListener, PostUpdateEventListener, and
PostDeleteEventListener using the following in an application:

beans = {
  auditListener(AuditEventListener)

  hibernateEventListeners(HibernateEventListeners) {
     listenerMap = ['post-insert': auditListener,
                    'post-update': auditListener,
                    'post-delete': auditListener]
  }
}

So I assume it should just work, and the AuditEventListener here should be
the hibernate envers one. Strangely, since  Envers is included as a
Hibernate core module from 3.5 and grails 2 bundled with hibernate 3.6, but
I still have to declared envers dependency from BuildConfig.groovy in order
for it to be picked up. I thought maybe just something was missed or
mis-configured.. anyway, will check out hibernate envers plugin see if I can
get it work with grails 2


I actually looked into that when you mentioned it being a 'hibernate core module' in your first email, and I think you are misunderstanding the concept.  It is still an optional addition to hibernate-core via its own jar, but it is now part of the hibernate project rather than a separate jboss project.

The old project was known as jboss-envers and came via a groupId of org.jboss.envers and an artifact of jboss-envers, with its website being part of jboss.org.  Now, it is hibernate-envers and comes via a groupId of org.hibernate and an artifactId of hibernate-envers, and you'll find documentation and support via the hibernate.org website.


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Grails 2.0.3 with hibernate Envers

GrailsUser001
This post has NOT been accepted by the mailing list yet.
In reply to this post by chris.zhao
Hi,

for us grails 2.0.x works fine togehter with hibernate envers (only JPA Embedded Ids makes some problems)...
Its good that the REV and _AUD tables get created. How are u trying to save the book instance? Are u doing it in an transaction? If not make sure its transactional because envers is based on hibernate transactions .. if u do a save() in a controller (no transaction) the changes will be persisted but NOT audited...

Cheers
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Grails 2.0.3 with hibernate Envers

chris.zhao
This post was updated on .
GrailsUser001 is right, calling save() in a grails service method with transactional = true (default value) makes hibernate envers start working again, many thanks!
Loading...