mstein / elasticsearch-grails-plugin

ElasticSearch grails plugin
Based on Graeme Rocher initial stub. Note that it is still in early stage.
Other
62 stars 164 forks source link

Could not open Hibernate Session for transaction - when making service calls in Bootstrap.groovy #11

Closed berinle closed 12 years ago

berinle commented 12 years ago

Apologies for double posting...

So I start a vanilla grails application, create an entity, a service with one method to save some instances of my entity and then in BootStrap.groovy, I call the service method.

I then added elasticsearch plugin.

Now when I invoke run-app, I get an error

Caused by CannotCreateTransactionException: Could not open Hibernate Session for transaction; nested exception is org.hibernate.SessionException: Session is closed!

which makes no sense, since services has a transaction wired in by default.

My domain: class Foo {

    String name 

static searchable = true 

static constraints = { 
} 

}

My service: class SimpleService {

def serviceMethod() { 
  10.times { 
  new Foo(name:'some-name-' + new Date()).save(flush:true) 
  } 

  println 'finished saving 10 foos' 
} 

}

Bootstrap: class BootStrap {

    def simpleService 

def init = { servletContext -> 
println 'calling service method' 
simpleService.serviceMethod() 
println 'ending call!' 
} 

def destroy = { 
} 

}

If I remove

static searchable = true

on the domain, the error goes away and things work as expected.

Can someone please shed some light on this?

Thanks.

PS: You can find the sample project @ https://github.com/berinle/grails-search-app, if you want something to test with or see the error in action.

Also: I posted on the grails user forum @ http://grails.1312388.n4.nabble.com/elastic-search-plugin-mysteries-td4366648.html

mstein commented 12 years ago

It seems there is an issue in Grails 2.0 with the bulk indexing on startup. Add

elasticSearch.bulkIndexOnStartup = false

in your Config.groovy for a workaround for now. I'll look into this issue asap.

berinle commented 12 years ago

Cool. Thanks Stephane. That works. Awesome plugin by the way. Keep up the good work!

smaldini commented 12 years ago

Lol it was Manuarii !! :D

mstein commented 12 years ago

should be fixed with commit 19a29743a4bad84ad618d9b8dca26223d40f832b