Quantcast

committing .save()'d domain objects so that list() or find() can get to them

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

committing .save()'d domain objects so that list() or find() can get to them

M Stewart
Using straight Hibernate I can commit my newly created objects directly via the Session. This allows me, in an integration test, to have another piece of code query for the new object and actually find it.

I don't see anyplace that Grails gives me that level of control. I can call save() on a domain object but I have to pass a reference directly to the other bit of code because list() and findAll() won't find it (because it hasn't been committed.)

This makes it more difficult than it should be to write useful integration tests as 'grails test-app' deletes the data for all my domain objects at the end of every test. (Is there a way to turn this off? I found zero documentation on the wiki.)

Hope this doesn't come across as overly pissy. I've been using Grails, on and off, for four months and I'm still coming across new 'conventions' that get in my way of getting stuff done.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: committing .save()'d domain objects so that list() or find() can get to them

Mike Hugo
if you're using Grails RC1, you could try

class FooTests extends GroovyTestCase {

    void testSomething() {
                def f = new Foo(name:'myname')
                f.save(flush:true)
               
                assertEquals (1, Foo.list().size())
    }
}

See http://grails.codehaus.org/1.0-RC1+Release+Notes#1.0-RC1ReleaseNotes-Sessionflushingcontrol


M Stewart wrote
Using straight Hibernate I can commit my newly created objects directly via the Session. This allows me, in an integration test, to have another piece of code query for the new object and actually find it.

I don't see anyplace that Grails gives me that level of control. I can call save() on a domain object but I have to pass a reference directly to the other bit of code because list() and findAll() won't find it (because it hasn't been committed.)

This makes it more difficult than it should be to write useful integration tests as 'grails test-app' deletes the data for all my domain objects at the end of every test. (Is there a way to turn this off? I found zero documentation on the wiki.)

Hope this doesn't come across as overly pissy. I've been using Grails, on and off, for four months and I'm still coming across new 'conventions' that get in my way of getting stuff done.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: committing .save()'d domain objects so that list() or find() can get to them

M Stewart
Hi Mike,

Thanks for the quick response. I wish I had a better response.

I am using RC1 from the trunk and the following fails on the second assertion when run as an integration test:

String guid = "123456789"
def org = new Org(id:guid, organizationName:"Baz", region:"US", creationDate: new Date())
assert org
org.save(flush:true)
assertEquals (1, Org.list().size())

Argh!

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

Re: committing .save()'d domain objects so that list() or find() can get to them

M Stewart
I just tried more or less the same code with a Groovy domain class and it worked fine. So maybe this is another issue with Java classes?
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: committing .save()'d domain objects so that list() or find() can get to them

Graeme Rocher
In reply to this post by M Stewart
You're sure you're not gettig a validation failure that you're not aware of?

Cheers

On 11/6/07, M Stewart <[hidden email]> wrote:

>
> Hi Mike,
>
> Thanks for the quick response. I wish I had a better response.
>
> I am using RC1 from the trunk and the following fails on the second
> assertion when run as an integration test:
>
> String guid = "123456789"
> def org = new Org(id:guid, organizationName:"Baz", region:"US",
> creationDate: new Date())
> assert org
> org.save(flush:true)
> assertEquals (1, Org.list().size())
>
> Argh!
>
>
> --
> View this message in context: http://www.nabble.com/committing-.save%28%29%27d-domain-objects-so-that-list%28%29-or-find%28%29-can-get-to-them-tf4761217.html#a13617515
> Sent from the grails - user mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe from this list please visit:
>
>     http://xircles.codehaus.org/manage_email
>
>


--
Graeme Rocher
Grails Project Lead
G2One, Inc. Chief Technology Officer
http://www.g2one.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
star

Re: committing .save()'d domain objects so that list() or find() can get to them

M Stewart
Graeme Rocher-2 wrote
You're sure you're not gettig a validation failure that you're not aware of?
Not that I'm aware of. ;-)

The test-app target completes cleanly. The only stack trace is the one created by the assertion and it contains nothing but the call stack. The assertion is after the domain object has been created and saved (with flush:true.) I don't suppose there's another log file I should be looking at?

FWIW I did an update of my SVN sandbox to make sure I wasn't missing a recent fix but it doesn't make a difference.

I also created a stand alone app with just a single Java domain class that reproduces the problem. I wasn't able to figure out how to get the memory-only Hsqldb config to work in this arrangement. Rather I had to use a real database--Oracle, in this case--which could mean the problem is db/driver specific. I'll try to

Here's the test:

      def f = new Baz(name:'Lurman')
      f.save(flush:true)
     
      assertEquals (1, Baz.list().size())

Should I open a bug in JIRA and attach the standalone app? I'll try to find some time to try mySQL in the meantime.


P.S. TransactionalServiceReloadTests is failing for me btw:

run-test:
   [delete] Deleting directory /data/dev/grails/trunk/grails/target/test-reports
    [mkdir] Created dir: /data/dev/grails/trunk/grails/target/test-reports
     [echo] Test being run * from target/test-classes
    [junit] java.io.FileNotFoundException: /data/dev/grails/trunk/grails/junitvmwatcher280132241.properties (No such file or directory)
    [junit] at java.io.FileInputStream.open(Native Method)
    [junit] at java.io.FileInputStream.<init>(FileInputStream.java:106)
    [junit] at java.io.FileReader.<init>(FileReader.java:55)
    [junit] at org.apache.tools.ant.taskdefs.optional.junit.JUnitTask.executeAsForked(JUnitTask.java:1028)
    [junit] at org.apache.tools.ant.taskdefs.optional.junit.JUnitTask.execute(JUnitTask.java:817)
    [junit] at org.apache.tools.ant.taskdefs.optional.junit.JUnitTask.execute(JUnitTask.java:780)
    [junit] at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:288)
    [junit] at sun.reflect.GeneratedMethodAccessor2.invoke(Unknown Source)
    [junit] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    [junit] at java.lang.reflect.Method.invoke(Method.java:585)
    [junit] at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:105)
    [junit] at org.apache.tools.ant.Task.perform(Task.java:348)
    [junit] at org.apache.tools.ant.Target.execute(Target.java:357)
    [junit] at org.apache.tools.ant.Target.performTasks(Target.java:385)
    [junit] at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1329)
    [junit] at org.apache.tools.ant.Project.executeTarget(Project.java:1298)
    [junit] at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
    [junit] at org.apache.tools.ant.Project.executeTargets(Project.java:1181)
    [junit] at org.apache.tools.ant.Main.runBuild(Main.java:698)
    [junit] at org.apache.tools.ant.Main.startAnt(Main.java:199)
    [junit] at org.apache.tools.ant.launch.Launcher.run(Launcher.java:257)
    [junit] at org.apache.tools.ant.launch.Launcher.main(Launcher.java:104)
    [junit] Test org.codehaus.groovy.grails.reload.TransactionalServiceReloadTests FAILED (crashed)
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: committing .save()'d domain objects so that list() or find() can get to them

Graeme Rocher
On 11/7/07, M Stewart <[hidden email]> wrote:

>
>
> Graeme Rocher-2 wrote:
> >
> > You're sure you're not gettig a validation failure that you're not aware
> > of?
> >
> Not that I'm aware of. ;-)
>
> The test-app target completes cleanly. The only stack trace is the one
> created by the assertion and it contains nothing but the call stack. The
> assertion is after the domain object has been created and saved (with
> flush:true.) I don't suppose there's another log file I should be looking
> at?
>
> FWIW I did an update of my SVN sandbox to make sure I wasn't missing a
> recent fix but it doesn't make a difference.
>
> I also created a stand alone app with just a single Java domain class that
> reproduces the problem. I wasn't able to figure out how to get the
> memory-only Hsqldb config to work in this arrangement. Rather I had to use a
> real database--Oracle, in this case--which could mean the problem is
> db/driver specific. I'll try to
>
> Here's the test:
>
>       def f = new Baz(name:'Lurman')
>       f.save(flush:true)
>
>       assertEquals (1, Baz.list().size())
>
> Should I open a bug in JIRA and attach the standalone app?


That would be useful yes

Cheers

 I'll try to find

> some time to try mySQL in the meantime.
>
>
> P.S. TransactionalServiceReloadTests is failing for me btw:
>
> run-test:
>    [delete] Deleting directory
> /data/dev/grails/trunk/grails/target/test-reports
>     [mkdir] Created dir: /data/dev/grails/trunk/grails/target/test-reports
>      [echo] Test being run * from target/test-classes
>     [junit] java.io.FileNotFoundException:
> /data/dev/grails/trunk/grails/junitvmwatcher280132241.properties (No such
> file or directory)
>     [junit]     at java.io.FileInputStream.open(Native Method)
>     [junit]     at java.io.FileInputStream.<init>(FileInputStream.java:106)
>     [junit]     at java.io.FileReader.<init>(FileReader.java:55)
>     [junit]     at
> org.apache.tools.ant.taskdefs.optional.junit.JUnitTask.executeAsForked(JUnitTask.java:1028)
>     [junit]     at
> org.apache.tools.ant.taskdefs.optional.junit.JUnitTask.execute(JUnitTask.java:817)
>     [junit]     at
> org.apache.tools.ant.taskdefs.optional.junit.JUnitTask.execute(JUnitTask.java:780)
>     [junit]     at
> org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:288)
>     [junit]     at sun.reflect.GeneratedMethodAccessor2.invoke(Unknown Source)
>     [junit]     at
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
>     [junit]     at java.lang.reflect.Method.invoke(Method.java:585)
>     [junit]     at
> org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:105)
>     [junit]     at org.apache.tools.ant.Task.perform(Task.java:348)
>     [junit]     at org.apache.tools.ant.Target.execute(Target.java:357)
>     [junit]     at org.apache.tools.ant.Target.performTasks(Target.java:385)
>     [junit]     at
> org.apache.tools.ant.Project.executeSortedTargets(Project.java:1329)
>     [junit]     at
> org.apache.tools.ant.Project.executeTarget(Project.java:1298)
>     [junit]     at
> org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
>     [junit]     at
> org.apache.tools.ant.Project.executeTargets(Project.java:1181)
>     [junit]     at org.apache.tools.ant.Main.runBuild(Main.java:698)
>     [junit]     at org.apache.tools.ant.Main.startAnt(Main.java:199)
>     [junit]     at org.apache.tools.ant.launch.Launcher.run(Launcher.java:257)
>     [junit]     at org.apache.tools.ant.launch.Launcher.main(Launcher.java:104)
>     [junit] Test
> org.codehaus.groovy.grails.reload.TransactionalServiceReloadTests FAILED
> (crashed)
> --
> View this message in context: http://www.nabble.com/committing-.save%28%29%27d-domain-objects-so-that-list%28%29-or-find%28%29-can-get-to-them-tf4761217.html#a13629651
> Sent from the grails - user mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe from this list please visit:
>
>     http://xircles.codehaus.org/manage_email
>
>


--
Graeme Rocher
Grails Project Lead
G2One, Inc. Chief Technology Officer
http://www.g2one.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
star

Re: committing .save()'d domain objects so that list() or find() can get to them

M Stewart
Loading...