FindAll is not supported in this implementation of GORM

I try to check a method in my service, but I get an error all the time, which

String-based queries, such as [findAll], are not currently supported in this GORM implementation. Use criteria instead.

My service:

class MyService {
  List<Color> colorShade (String shade) {
    def shadeId = Shade.findByName(shade).id
    return ColorShade.get(shadeId)      
  }
}

My class that integrates Shadeand Colordomains

class ColorShade extends Serializable {
  Color color
  Shade shade
  static ColorShade create (Color color, Shade shade, boolean flush = false) {
    if (get(shade.id) == null)
        new ColorNetwork(color: color, shade: shade).save(flush:  flush)
  }

   static ColorShade get (long shadeId) {
        ColorShade.findAll 'from ColorShade where shade.id = :shadeId',
                [shadeId: shadeId]
    }
    static mapping = {
        table 'color_shade'
        version false
        id composite: ['color', 'shade']
    }
}

My specification: test\unit\MyServiceSpec.groovyI also tried adding it totest\integration\MyServiceSpec.groovy

@TestFor(MyServiceSpec)
@Mock([Color, Shade, ColorNetwork])
@TestMixin(DomainClassUnitTestMixin)
class MyServiceSpec extends Specification {

    def shade
    def color
  def setup(){
    color = new Color(name: "red")
    shade = new Shade(name: "dark")
    color.save(flush: true)
    shade.save(flush: true)

    ColorShade.create(color, shade)
    /* 
    I've also tried:
    mockDomain(ColorShade, [[color: color, shade: shade]])
    but I get the same error
    */

  }
  def cleanup () {
  }

  def "test colorShade" () {
    expect:
       1 == service.colorShade("dark").size()
  }
}

When I run this test, I get an error message:

String-based queries like [findAll] are currently not supported in this implementation of GORM. Use criteria instead.

Question

  • How can I check this? I'm on grails 2.2.4

Note. This is just a sample test case that I created for the purpose of the question. My actual tests are different, but in them I have the same problem as this question.

+4
1

4.3.5.4 hibernate4, grails.test.mixin.hibernate.HibernateTestMixin, Hibernate GORM unit test. - grails-app/conf/BuildConfig.groovy.

dependencies {
    test "org.grails:grails-datastore-test-support:1.0-grails-2.4"
}

grails.test.mixin.hibernate.HibernateTestMixin.

+2

Source: https://habr.com/ru/post/1545760/


All Articles