MongoDB GORM persistence events

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

MongoDB GORM persistence events

Jesper Zedlitz
Hi, 

I am using a persistence event listener. It works fine with the Hibernate GORM backend. However, it does not work with the MonoDB GORM backend. Even a very simple test (with a fresh Grails 2.4.3 application) fails. My BootStrap.groovy contains this code:
  def init = { servletContext ->
     grailsApplication.mainContext.eventTriggeringInterceptor.datastores.each { k, datastore ->
        servletContext.getAttribute(ApplicationAttributes.APPLICATION_CONTEXT) .addApplicationListener new MyPersistenceListener(datastore)
     }
  }

After replacing these two lines in BuildConfig.groovy
  runtime ":hibernate4:4.3.5.5" // or ":hibernate:3.6.10.17"
  runtime ":database-migration:1.4.0"
with
  runtime ":mongodb:3.0.2"
the application won't even start anymore:
  | Error 2014-09-22 13:50:39,480 [localhost-startStop-1] ERROR context.GrailsContextLoaderListener  - Error initializing the application: Cannot get property 'datastores' on null object
  Message: Cannot get property 'datastores' on null object
      Line | Method
  ->>    7 | doCall                           in BootStrap$_closure1

Are persistence events not supported by the MongoDB GORM backed?

Regards,
Jesper

--
You received this message because you are subscribed to the Google Groups "Grails Dev Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/grails-dev-discuss/a0d8cf61-a029-440f-a761-1348943466da%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: MongoDB GORM persistence events

Graeme Rocher-2
the bean "eventTriggeringInterceptor" is specific to hibernate and
shouldn't be used directly. Register your listener as a spring bean
itself and it will be picked up

Cheers

On Mon, Sep 22, 2014 at 1:56 PM, Jesper Zedlitz
<[hidden email]> wrote:

> Hi,
>
> I am using a persistence event listener. It works fine with the Hibernate
> GORM backend. However, it does not work with the MonoDB GORM backend. Even a
> very simple test (with a fresh Grails 2.4.3 application) fails. My
> BootStrap.groovy contains this code:
>   def init = { servletContext ->
>
> grailsApplication.mainContext.eventTriggeringInterceptor.datastores.each {
> k, datastore ->
>
> servletContext.getAttribute(ApplicationAttributes.APPLICATION_CONTEXT)
> .addApplicationListener new MyPersistenceListener(datastore)
>      }
>   }
>
> After replacing these two lines in BuildConfig.groovy
>   runtime ":hibernate4:4.3.5.5" // or ":hibernate:3.6.10.17"
>   runtime ":database-migration:1.4.0"
> with
>   runtime ":mongodb:3.0.2"
> the application won't even start anymore:
>   | Error 2014-09-22 13:50:39,480 [localhost-startStop-1] ERROR
> context.GrailsContextLoaderListener  - Error initializing the application:
> Cannot get property 'datastores' on null object
>   Message: Cannot get property 'datastores' on null object
>       Line | Method
>   ->>    7 | doCall                           in BootStrap$_closure1
>
> Are persistence events not supported by the MongoDB GORM backed?
>
> Regards,
> Jesper
>
> --
> You received this message because you are subscribed to the Google Groups
> "Grails Dev Discuss" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [hidden email].
> To post to this group, send email to [hidden email].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/grails-dev-discuss/a0d8cf61-a029-440f-a761-1348943466da%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.



--
Graeme Rocher
Grails Project Lead
Pivotal

--
You received this message because you are subscribed to the Google Groups "Grails Dev Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/grails-dev-discuss/CAO_wNoeTKryAQ5yspcxPYcUC4726amy0OsOpr6UCGaocZnUvKw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: MongoDB GORM persistence events

Graeme Rocher-2
Alternatively you can use

grailsApplication.mainContext.addApplicationListener(listener)

On Mon, Sep 22, 2014 at 2:01 PM, Graeme Rocher <[hidden email]> wrote:

> the bean "eventTriggeringInterceptor" is specific to hibernate and
> shouldn't be used directly. Register your listener as a spring bean
> itself and it will be picked up
>
> Cheers
>
> On Mon, Sep 22, 2014 at 1:56 PM, Jesper Zedlitz
> <[hidden email]> wrote:
>> Hi,
>>
>> I am using a persistence event listener. It works fine with the Hibernate
>> GORM backend. However, it does not work with the MonoDB GORM backend. Even a
>> very simple test (with a fresh Grails 2.4.3 application) fails. My
>> BootStrap.groovy contains this code:
>>   def init = { servletContext ->
>>
>> grailsApplication.mainContext.eventTriggeringInterceptor.datastores.each {
>> k, datastore ->
>>
>> servletContext.getAttribute(ApplicationAttributes.APPLICATION_CONTEXT)
>> .addApplicationListener new MyPersistenceListener(datastore)
>>      }
>>   }
>>
>> After replacing these two lines in BuildConfig.groovy
>>   runtime ":hibernate4:4.3.5.5" // or ":hibernate:3.6.10.17"
>>   runtime ":database-migration:1.4.0"
>> with
>>   runtime ":mongodb:3.0.2"
>> the application won't even start anymore:
>>   | Error 2014-09-22 13:50:39,480 [localhost-startStop-1] ERROR
>> context.GrailsContextLoaderListener  - Error initializing the application:
>> Cannot get property 'datastores' on null object
>>   Message: Cannot get property 'datastores' on null object
>>       Line | Method
>>   ->>    7 | doCall                           in BootStrap$_closure1
>>
>> Are persistence events not supported by the MongoDB GORM backed?
>>
>> Regards,
>> Jesper
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Grails Dev Discuss" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to [hidden email].
>> To post to this group, send email to [hidden email].
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/grails-dev-discuss/a0d8cf61-a029-440f-a761-1348943466da%40googlegroups.com.
>> For more options, visit https://groups.google.com/d/optout.
>
>
>
> --
> Graeme Rocher
> Grails Project Lead
> Pivotal



--
Graeme Rocher
Grails Project Lead
Pivotal

--
You received this message because you are subscribed to the Google Groups "Grails Dev Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/grails-dev-discuss/CAO_wNocnGNNM_8amwQNSihcCM0g2VJ%2BeDN8nq8FCaDSwx6y_ng%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: MongoDB GORM persistence events

Jesper Zedlitz
Alternatively you can use

grailsApplication.mainContext.addApplicationListener(listener)
 
That would make it much easier. An AbstractPersistenceEventListener needs a Datastore instance as constructor parameter. How do I find the correct object?

--
You received this message because you are subscribed to the Google Groups "Grails Dev Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/grails-dev-discuss/ed0263a1-763c-4032-81ae-79779aadc1e2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: MongoDB GORM persistence events

Graeme Rocher-2
mainContext.getBean(Datastore)

On Mon, Sep 22, 2014 at 8:39 PM, Jesper Zedlitz
<[hidden email]> wrote:

>> Alternatively you can use
>>
>> grailsApplication.mainContext.addApplicationListener(listener)
>>
>>
>
> That would make it much easier. An AbstractPersistenceEventListener needs a
> Datastore instance as constructor parameter. How do I find the correct
> object?
>
> --
> You received this message because you are subscribed to the Google Groups
> "Grails Dev Discuss" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [hidden email].
> To post to this group, send email to [hidden email].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/grails-dev-discuss/ed0263a1-763c-4032-81ae-79779aadc1e2%40googlegroups.com.
>
> For more options, visit https://groups.google.com/d/optout.



--
Graeme Rocher
Grails Project Lead
Pivotal

--
You received this message because you are subscribed to the Google Groups "Grails Dev Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/grails-dev-discuss/CAO_wNodqueJ6Lca4pnd5tJfKeXSpvjDpTFFncpEHVLsV25BpqQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: MongoDB GORM persistence events

Jesper Zedlitz
Thank you very much for the hints so far. I have been able to register a custom persistence listener by adding these lines to BootStrap.groovy
  grailsApplication.mainContext.getBeansOfType(Datastore).values().each { ds ->
     grailsApplication.mainContext.addApplicationListener(new MyPersistenceListener(ds))
  }

An interesting observation - and I am leaving the topic of this thread a bit - is that the MongoDB datastore sets the event.entity field the Hibernate datastore does not set the field. Therefore I have to check the class of the entityObject for a general solution.

--
You received this message because you are subscribed to the Google Groups "Grails Dev Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/grails-dev-discuss/15ad72f7-12b8-41b6-9c36-2b92ba9ede18%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
RRK
Reply | Threaded
Open this post in threaded view
|

NEWBEE - Error:[localhost-startStop-1] ERROR context.GrailsContextLoaderListener

RRK
This post has NOT been accepted by the mailing list yet.
In reply to this post by Graeme Rocher-2
Hello geeks! I am taking a quantum leap from a BIDW world into Groovy Grails and so far I like it!Do need your erudite and sage advice on the above error I run into. Below are the domain class, dataSource.groovy and buildCOnfig.groovy files.Thanks in advance for all your inputs: Scope of the effort: Build a simple screen to allow entries to a field(s) off a backend DB2 table and allow DMLs to be posted to the backend. Complete Error Link:MyErrPage.htm (Hope the uploaded file is viewable as a hyperlink! Otherwise, my apologies) I. Domain Class Code Class FM8 { float ALT_IVT_INSTRUMENT_ID = 15 static mapping = { //datasource 'ALL' table name: "FM8", schema: "BARS" } } II. DataSource.groovy dataSource { //jmxExport = true pooled = true driverClassName = "com.ibm.db2.jcc.DB2Driver" username = "xxxxx" password = "yyyyyyy" dialect = org.hibernate.dialect.DB2Dialect // jmxExport = true // driverClassName = "org.h2.Driver" // username = "sa" // password = "" // } hibernate { cache.use_second_level_cache = true cache.use_query_cache = false //hibernate.default_schema = "BARSGLOBAL" //cache.region.factory_class = 'net.sf.ehcache.hibernate.EhCacheRegionFactory' // Hibernate 3 cache.region.factory_class = 'org.hibernate.cache.ehcache.EhCacheRegionFactory' // Hibernate 4 //singleSession = true // configure OSIV singleSession mode flush.mode = 'AUTO' // OSIV session flush mode outside of transactional context } // environment specific settings environments { development { dataSource { //dbCreate = "update" // one of 'create', 'create-drop', 'update', 'validate', '' dbCreate = "validate" // one of 'create', 'create-drop', 'update', 'validate', '' //url = "jdbc:h2:mem:devDb;MVCC=TRUE;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE" url = "jdbc:db2://wdc-aixbetadb-37.m.dstcorp.net:50000/BRDT004F" } } } test { dataSource { dbCreate = "update" url = "jdbc:h2:mem:testDb;MVCC=TRUE;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE" } } production { dataSource { dbCreate = "update" url = "jdbc:h2:prodDb;MVCC=TRUE;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE" properties { // See http://grails.org/doc/latest/guide/conf.html#dataSource for documentation jmxEnabled = true initialSize = 5 maxActive = 50 minIdle = 5 maxIdle = 25 maxWait = 10000 maxAge = 10 * 60000 timeBetweenEvictionRunsMillis = 5000 minEvictableIdleTimeMillis = 60000 validationQuery = "SELECT 1" validationQueryTimeout = 3 validationInterval = 15000 testOnBorrow = true testWhileIdle = true testOnReturn = false jdbcInterceptors = "ConnectionState" defaultTransactionIsolation = java.sql.Connection.TRANSACTION_READ_COMMITTED } } } III.BuildConfig.groovy grails.servlet.version = "3.0" // Change depending on target container compliance (2.5 or 3.0) grails.project.class.dir = "target/classes" grails.project.test.class.dir = "target/test-classes" grails.project.test.reports.dir = "target/test-reports" grails.project.work.dir = "target/work" grails.project.target.level = 1.6 grails.project.source.level = 1.6 //grails.project.war.file = "target/${appName}-${appVersion}.war" grails.project.fork = [ // configure settings for compilation JVM, note that if you alter the Groovy version forked compilation is required // compile: [maxMemory: 256, minMemory: 64, debug: false, maxPerm: 256, daemon:true], // configure settings for the test-app JVM, uses the daemon by default test: [maxMemory: 768, minMemory: 64, debug: false, maxPerm: 256, daemon:true], // configure settings for the run-app JVM run: [maxMemory: 768, minMemory: 64, debug: false, maxPerm: 256, forkReserve:false], // configure settings for the run-war JVM war: [maxMemory: 768, minMemory: 64, debug: false, maxPerm: 256, forkReserve:false], // configure settings for the Console UI JVM console: [maxMemory: 768, minMemory: 64, debug: false, maxPerm: 256] ] grails.project.dependency.resolver = "maven" // or ivy grails.project.dependency.resolution = { // inherit Grails' default dependencies inherits("global") { // specify dependency exclusions here; for example, uncomment this to disable ehcache: //excludes 'ehcache' } log "error" // log level of Ivy resolver, either 'error', 'warn', 'info', 'debug' or 'verbose' checksums true // Whether to verify checksums on resolve legacyResolve false // whether to do a secondary resolve on plugin installation, not advised and here for backwards compatibility repositories { inherits true // Whether to inherit repository definitions from plugins grailsPlugins() grailsHome() mavenLocal() grailsCentral() mavenCentral() // uncomment these (or add new ones) to enable remote dependency resolution from public Maven repositories //mavenRepo "http://repository.codehaus.org" //mavenRepo "http://download.java.net/maven/2/" //mavenRepo "http://repository.jboss.com/maven2/" } dependencies { // specify dependencies here under either 'build', 'compile', 'runtime', 'test' or 'provided' scopes e.g. // runtime 'mysql:mysql-connector-java:5.1.29' //runtime 'org.hibernate.dialect.DB2Dialect' // runtime 'org.postgresql:postgresql:9.3-1101-jdbc41' test "org.grails:grails-datastore-test-support:1.0.2-grails-2.4" } plugins { // plugins for the build system only build ":tomcat:7.0.55" // plugins for the compile step compile ":scaffolding:2.1.2" compile ':cache:1.1.8' compile ":asset-pipeline:1.9.9" // plugins needed at runtime but not for compilation //runtime ":hibernate4:4.3.6.1" // or ":hibernate:3.6.10.18" runtime ":hibernate4:4.3.5.5" // or ":hibernate:3.6.10.18" runtime ":database-migration:1.4.0" runtime ":jquery:1.11.1" // Uncomment these to enable additional asset-pipeline capabilities //compile ":sass-asset-pipeline:1.9.0" //compile ":less-asset-pipeline:1.10.0" //compile ":coffee-asset-pipeline:1.8.0" //compile ":handlebars-asset-pipeline:1.3.0.3" } } Thanks RRK