Alex Rivera | Logout

Grails Unit Test "CreateAlias" doesn´t work

Asked 2012-10-23T07:53:15.620
9

I am trying to make a unit test over a namedquery method and it´s not working as I am using the method grails.orm.HibernateCriteriaBuilder.createAlias which doesn´t seem to be found by Grails: " No signature of method: grails.gorm.CriteriaBuilder.createAlias()"

I guess the problem is that when making a unit test and mocking the class, it´s trying to find the method around "grails.gorm.CriteriaBuilder" class and not grails.orm.HibernateCriteriaBuilder class, why ?? any ideas to solve it?

class Book{
  static namedQueries = {     
      testMethod()
      {
         createAlias('name', 'james')
      }
   }
}



@Mock([Book])
class BookTests{
  @Test
  void myTest() {
      Book.testMethod();
   }
}

Error : No signature of method: grails.gorm.CriteriaBuilder.createAlias()

Edit
Report

1 Answer

2

We couldn't figure this out either; we suspect it's just missing from the GORM UnitTest implementation. But if you just want to query an association, in Grails you don't need an alias. Observe:

Book.createCriteria {
    eq("title", "One Hundred Years of Solitude")
    author {
        eq("name", "Gabriel García Márquez")
    }
}
answered 2012-11-16T16:15:41.450

Your Answer