Hibernate event listeners

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

Hibernate event listeners

Jon Sharp-4
Hi all,

I am attempting to wire up some custom Java classes implementing the SaveOrUpdateEventListener interface within my grails app and am having some difficulty seeing that these are wired properly.  I came across the section 5.5.1 in the guide, and I thought that would do it for me, but I get an ArrayStoreException when specifying my class as follows: 
beans = {

reservationSaveOrUpdateEventListener(ReservationSaveOrUpdateEventListener)

hibernateEventListeners(HibernateEventListeners) { listenerMap = ['save-update':reservationSaveOrUpdateEventListener] } }


I receive the ArrayStoreException whether I use the beanbuilder syntax above, or its equivalent spring xml.  It appears that it does not like my ReservationSaveOrUpdateEventListener class, attempting to store it in an array of objects of another type.  I have tried subclassing DefaultSaveOrUpdateEventListener or simply implementing the interface.  ASE occurs in either case.  

I have also attempted to wire it up using the hibernate.cfg.xml file, but the <listener/> elements appear to be ignored.

I know that Grails provides the closure approach for these event listeners, but I need this class to live in another lib and used by other projects.  I'm hopeful that this is a simple thing that I'm missing somewhere and would be grateful for any pointers.

Thanks again,
Jon

--
Jon Sharp
CTO & Senior Engineer
Campground Automation Systems, Inc.
(615) 681-1100





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

Re: Hibernate event listeners

basejump (Josh)
1. you do have the imports for your listener and the HibernateEventListeners at the top of your resources file right?

2. If you want to share this across grails app then you won't be able to do it like this and put it in a lib. You will need to make a plugin and put your bean defs in doWithSpring of your plugin file


On Apr 29, 2011, at 9:21 AM, Jon Sharp wrote:

Hi all,

I am attempting to wire up some custom Java classes implementing the SaveOrUpdateEventListener interface within my grails app and am having some difficulty seeing that these are wired properly.  I came across the section 5.5.1 in the guide, and I thought that would do it for me, but I get an ArrayStoreException when specifying my class as follows: 
beans = {

reservationSaveOrUpdateEventListener(ReservationSaveOrUpdateEventListener)

hibernateEventListeners(HibernateEventListeners) { listenerMap = ['save-update':reservationSaveOrUpdateEventListener] } }


I receive the ArrayStoreException whether I use the beanbuilder syntax above, or its equivalent spring xml.  It appears that it does not like my ReservationSaveOrUpdateEventListener class, attempting to store it in an array of objects of another type.  I have tried subclassing DefaultSaveOrUpdateEventListener or simply implementing the interface.  ASE occurs in either case.  

I have also attempted to wire it up using the hibernate.cfg.xml file, but the <listener/> elements appear to be ignored.

I know that Grails provides the closure approach for these event listeners, but I need this class to live in another lib and used by other projects.  I'm hopeful that this is a simple thing that I'm missing somewhere and would be grateful for any pointers.

Thanks again,
Jon

--
Jon Sharp
CTO & Senior Engineer
Campground Automation Systems, Inc.
(615) 681-1100






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

Re: Hibernate event listeners

Jon Sharp-4
> On Apr 29, 2011, at 12:07 PM, basejump (Josh) wrote:
>
>> 1. you do have the imports for your listener and the HibernateEventListeners at the top of your resources file right?
>>

Yes, in the case of resources.groovy.  I have also defined it within our existing resources.xml file, as well.  The exception isn't a class not found exception, but rather an ArrayStoreException, seemingly pointing to (by my best guess) the underlying arrays of event listeners in the SessionManager.  in this case, it seems to me that the exception is thrown in the attempt to store my instance in the array of type SaveOrUpdateEventListener[].  I'm not sure why this would happen, exactly, as my class implements that interface.  Perhaps the Groovyness in middle of this logic is doing something?  

>> 2. If you want to share this across grails app then you won't be able to do it like this and put it in a lib. You will need to make a plugin and put your bean defs in doWithSpring of your plugin file
>

I understand that.  My desire is to have these event listener classes provided in an external library by which any spring app can wire up at runtime.  I was hoping that others were using external event listener classes (as opposed to the closure approach) within their grails apps and could confirm the proper approach there.  It should also be noted that if I create an instance of my custom listener class and specifically store that in the array of SaveOrUpdateEventListener's on the SessionManager, my listener works as it should.

Thanks,
Jon

--
Jon Sharp
CTO & Senior Engineer
Campground Automation Systems, Inc.
[hidden email]
(615) 681-1100
www.campgroundautomation.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

Re: Hibernate event listeners

basejump (Josh)
We are doing something similar  here
http://svn.codehaus.org/grails-plugins/grails-audit-trail/trunk/AuditTrailGrailsPlugin.groovy
Using defining the entityInterceptor bean instead and extends org.hibernate.EmptyInterceptor


On Apr 29, 2011, at 12:38 PM, Jon Sharp wrote:

>> On Apr 29, 2011, at 12:07 PM, basejump (Josh) wrote:
>>
>>> 1. you do have the imports for your listener and the HibernateEventListeners at the top of your resources file right?
>>>
>
> Yes, in the case of resources.groovy.  I have also defined it within our existing resources.xml file, as well.  The exception isn't a class not found exception, but rather an ArrayStoreException, seemingly pointing to (by my best guess) the underlying arrays of event listeners in the SessionManager.  in this case, it seems to me that the exception is thrown in the attempt to store my instance in the array of type SaveOrUpdateEventListener[].  I'm not sure why this would happen, exactly, as my class implements that interface.  Perhaps the Groovyness in middle of this logic is doing something?  
>
>>> 2. If you want to share this across grails app then you won't be able to do it like this and put it in a lib. You will need to make a plugin and put your bean defs in doWithSpring of your plugin file
>>
>
> I understand that.  My desire is to have these event listener classes provided in an external library by which any spring app can wire up at runtime.  I was hoping that others were using external event listener classes (as opposed to the closure approach) within their grails apps and could confirm the proper approach there.  It should also be noted that if I create an instance of my custom listener class and specifically store that in the array of SaveOrUpdateEventListener's on the SessionManager, my listener works as it should.
>
> Thanks,
> Jon
>
> --
> Jon Sharp
> CTO & Senior Engineer
> Campground Automation Systems, Inc.
> [hidden email]
> (615) 681-1100
> www.campgroundautomation.com
> ---------------------------------------------------------------------
> To unsubscribe from this list, please visit:
>
>    http://xircles.codehaus.org/manage_email
>
>


---------------------------------------------------------------------
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

Re: Hibernate event listeners

Jon Sharp-4
Josh,

I see that you are using the hibernate Interceptor interface in this example.  I've been attempting to use the Event system documented here: http://docs.jboss.org/hibernate/core/3.3/reference/en-US/html/events.html.  It seems that each one is a valid hibernate approach, and that they can even be used together. ("The event system can be used in addition, or as a replacement, for interceptors.")  The Grails user guide seems to be endorsing the Hibernate event system (as opposed to the Interceptor approach.  At least, chapter 5 makes no mention of Interceptors.)  I read something (http://stackoverflow.com/questions/1545622/hibernate-event-listener-or-interceptor-what-are-the-pros-cons-in-practice) that indicated the EventListener was preferred, but I'm not clear on why that is.  In any case, I have an existing Spring (non-Grails) app that is deployed in addition to my Grails apps, one in which I will need to use these event listeners.

Thanks again,
Jon


On Apr 29, 2011, at 1:09 PM, basejump (Josh) wrote:

> We are doing something similar  here
> http://svn.codehaus.org/grails-plugins/grails-audit-trail/trunk/AuditTrailGrailsPlugin.groovy
> Using defining the entityInterceptor bean instead and extends org.hibernate.EmptyInterceptor
>
>
> On Apr 29, 2011, at 12:38 PM, Jon Sharp wrote:
>
>>> On Apr 29, 2011, at 12:07 PM, basejump (Josh) wrote:
>>>
>>>> 1. you do have the imports for your listener and the HibernateEventListeners at the top of your resources file right?
>>>>
>>
>> Yes, in the case of resources.groovy.  I have also defined it within our existing resources.xml file, as well.  The exception isn't a class not found exception, but rather an ArrayStoreException, seemingly pointing to (by my best guess) the underlying arrays of event listeners in the SessionManager.  in this case, it seems to me that the exception is thrown in the attempt to store my instance in the array of type SaveOrUpdateEventListener[].  I'm not sure why this would happen, exactly, as my class implements that interface.  Perhaps the Groovyness in middle of this logic is doing something?  
>>
>>>> 2. If you want to share this across grails app then you won't be able to do it like this and put it in a lib. You will need to make a plugin and put your bean defs in doWithSpring of your plugin file
>>>
>>
>> I understand that.  My desire is to have these event listener classes provided in an external library by which any spring app can wire up at runtime.  I was hoping that others were using external event listener classes (as opposed to the closure approach) within their grails apps and could confirm the proper approach there.  It should also be noted that if I create an instance of my custom listener class and specifically store that in the array of SaveOrUpdateEventListener's on the SessionManager, my listener works as it should.
>>
>> Thanks,
>> Jon
>>
>> --
>> Jon Sharp
>> CTO & Senior Engineer
>> Campground Automation Systems, Inc.
>> [hidden email]
>> (615) 681-1100
>> www.campgroundautomation.com
>> ---------------------------------------------------------------------
>> To unsubscribe from this list, please visit:
>>
>>   http://xircles.codehaus.org/manage_email
>>
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe from this list, please visit:
>
>    http://xircles.codehaus.org/manage_email
>
>


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

    http://xircles.codehaus.org/manage_email


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

Re: Hibernate event listeners

SN
Loading...