Hibernate listeners are not called for integration tests !

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
SN
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Hibernate listeners are not called for integration tests !

SN
In my sample plugin, I registered few Hibernate listeners, the listeners just prints message to console.

    def doWithSpring = {
       sanitizeHtmlListner(SanitizeHtmlListner)
hibernateEventListeners(HibernateEventListeners) {
  listenerMap = ['save':sanitizeHtmlListner,
 'update':sanitizeHtmlListner,
 'pre-update':sanitizeHtmlListner,
 'create':sanitizeHtmlListner,
 'save-update':sanitizeHtmlListner]
   }
    }
 

Both, SanitizeHtmlListner and HibernateEventListeners classes are imported.

In integration test

Book b = new Book()
b.name = "Sample book"
b.save()
println "Book ID :" + b.id
b.name = "Name changed"
b.save()

I just created this test, so that i can debug into the listeners, but none of the listener method is being called.
What am I doing wrong ?
SN
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Hibernate listeners are not called for integration tests !

SN

Don't know what happened, but now when i try to run the tests, it throws the exception (Somehow, initially it was not throwing exception, just won't invoke the listener)
  1. Error creating bean with name 'transactionManager': Cannot resolve reference to bean'sessionFactory' while setting
  2. bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationExceptionError creat
  3. ing bean with name 'sessionFactory': Invocation of init method failed; nested exception is java.lang.ArrayStoreExceptio.


   This is related to the Hibernate listener, 

Here's the related stuff http://pastebin.com/5Epxbb8Z



From: Sudhir N <[hidden email]>
To: Grails-user <[hidden email]>
Sent: Tuesday, 24 May 2011 1:22 PM
Subject: [grails-user] Hibernate listeners are not called for integration tests !

In my sample plugin, I registered few Hibernate listeners, the listeners just prints message to console.

    def doWithSpring = {
       sanitizeHtmlListner(SanitizeHtmlListner)
hibernateEventListeners(HibernateEventListeners) {
  listenerMap = ['save':sanitizeHtmlListner,
 'update':sanitizeHtmlListner,
 'pre-update':sanitizeHtmlListner,
 'create':sanitizeHtmlListner,
 'save-update':sanitizeHtmlListner]
   }
    }
 

Both, SanitizeHtmlListner and HibernateEventListeners classes are imported.

In integration test

Book b = new Book()
b.name = "Sample book"
b.save()
println "Book ID :" + b.id
b.name = "Name changed"
b.save()

I just created this test, so that i can debug into the listeners, but none of the listener method is being called.
What am I doing wrong ?


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

Re: Hibernate listeners are not called for integration tests !

SN
Just figured out that this is a bug :

Registering an event listener for "save, update etc" (SaveOrUpdateEventListener) Will cause ArrayStoreException at runtime . 
I just tried with "pre-insert" and it works without any issues. I don't know what all other event listeners will cause this issue.

Will report a bug in Jira

Thanks pledbrook, for help over IRC and getting the response from Graeme.

It can be reproduced easily using the code http://pastebin.com/Nf4rxy9U

Thanks
 

From: Sudhir N <[hidden email]>
To: "[hidden email]" <[hidden email]>
Sent: Tuesday, 24 May 2011 3:15 PM
Subject: Re: [grails-user] Hibernate listeners are not called for integration tests !


Don't know what happened, but now when i try to run the tests, it throws the exception (Somehow, initially it was not throwing exception, just won't invoke the listener)
  1. Error creating bean with name 'transactionManager': Cannot resolve reference to bean'sessionFactory' while setting
  2. bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationExceptionError creat
  3. ing bean with name 'sessionFactory': Invocation of init method failed; nested exception is java.lang.ArrayStoreExceptio.


   This is related to the Hibernate listener, 

Here's the related stuff http://pastebin.com/5Epxbb8Z



From: Sudhir N <[hidden email]>
To: Grails-user <[hidden email]>
Sent: Tuesday, 24 May 2011 1:22 PM
Subject: [grails-user] Hibernate listeners are not called for integration tests !

In my sample plugin, I registered few Hibernate listeners, the listeners just prints message to console.

    def doWithSpring = {
       sanitizeHtmlListner(SanitizeHtmlListner)
hibernateEventListeners(HibernateEventListeners) {
  listenerMap = ['save':sanitizeHtmlListner,
 'update':sanitizeHtmlListner,
 'pre-update':sanitizeHtmlListner,
 'create':sanitizeHtmlListner,
 'save-update':sanitizeHtmlListner]
   }
    }
 

Both, SanitizeHtmlListner and HibernateEventListeners classes are imported.

In integration test

Book b = new Book()
b.name = "Sample book"
b.save()
println "Book ID :" + b.id
b.name = "Name changed"
b.save()

I just created this test, so that i can debug into the listeners, but none of the listener method is being called.
What am I doing wrong ?




Loading...