grails run-script doesn't flush hibernate session

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

grails run-script doesn't flush hibernate session

Yuri Bendana-2
I'm a recent convert to Groovy/Grails and I'm using Grails 1.3.6.  I'm executing a simple script with run-script and I notice that if I don't add 'flush:true' to a save() the domain class is not persisted to the database when the script ends.  If I execute the same commands in the Grails shell or console, the Hibernate session is automatically flushed when I exit.  I noticed that this was a bug that was recently fixed in the Grails shell so I'm wondering if there is a bug in run-script.  Here's an example of what I'm executing:

import org.gmod.chado.*
env = new Environment(uniquename:'NaCl 0')
env.save()


thanks,

yuri 
Reply | Threaded
Open this post in threaded view
|

Re: grails run-script doesn't flush hibernate session

Yuri Bendana
Yuri Bendana-2 wrote
I'm a recent convert to Groovy/Grails and I'm using Grails 1.3.6.  I'm
executing a simple script with run-script and I notice that if I don't add
'flush:true' to a save() the domain class is not persisted to the database
when the script ends.  If I execute the same commands in the Grails shell or
console, the Hibernate session is automatically flushed when I exit.  I
noticed that this was a bug that was recently fixed in the Grails shell so
I'm wondering if there is a bug in run-script.  Here's an example of what
I'm executing:

import org.gmod.chado.*
env = new Environment(uniquename:'NaCl 0')
env.save()


thanks,

yuri
For anyone who runs into the same issue, I was able to work around it by wrapping the code in a transaction, as in Environment.withTransaction {...}.  I later decided to move this code into a service which is by default transactional. I can get a reference to it from my script using ctx.getBean('myService').