1. Grails
  2. GRAILS-8826

Named Query isNull in test context does not work on foreign key relations


    • Type: Bug Bug
    • Status: Closed
    • Priority: Critical Critical
    • Resolution: Fixed
    • Affects Version/s: 2.0.1
    • Fix Version/s: 2.0.4
    • Component/s: Persistence
    • Labels:
    • Environment:
      Grails v2.0.1 on IntelliJ IDEA v11


      We have the following model:
      class A {
        String name
        B b
        static namedQueries = {
      class B {}

      Furthermore, the following test is in place:
      import grails.test.mixin.*
      import static org.junit.Assert.assertEquals
      class ATests {
        void testIsNull() {
          new A(name: "alpha").save(flush: true, validate: false)
          def list = A.list()
          assertEquals(1, list.size())
          assertEquals("alpha", list.get(0).name)
          assertEquals(null, list.get(0).b)
          def results = A.withoutB
          assertEquals 1, results.count()

      What you see here is that an instance of type A is created, and that its field 'b' is null. This is proven by the assert statements in the testIsNull method, where the record is fetched and checked for a null value in field 'b'.

      Now the named query 'withoutB' is called, which must return all objects where 'b' is null. Note that this named query is defined in the body of class A.

      The result now is that no results are returned, instead of the expected 1 record.

      If isNull('b' is changed to isNotNull('b'), 1 result is returned.

      Remarkable is that isNull seems to work fine when the application is run under the full Grails context.

      It has all appearances that isNull in a test context has a different implementation from the real context and that the test context implementation has a bug.



          • Assignee:
            Graeme Rocher
            Robert Bor
          • Votes:
            1 Vote for this issue
            3 Start watching this issue


            • Created: