Skip to content
Advertisement

Groovy createCriteria issue with joined table

I have a domain class Coach which has a has many relationship to another domain class CoachProperty.

Hibernate/Grails is creating a third joined table in the database.

In the example below I am trying to fetch the coaches which both have foo AND bar for their text value. I have tried different solutions with ‘or’ and ‘and’ in Grails which either returns an empty list or a list with BOTH foo and bar.

Coach:

JavaScript

CoachProperty:

JavaScript

Joined table which is being auto-created and I populated with some data, in this example I am trying to fetch coach 372 since that coach has both 1 and 2 i.e foo and bar:

JavaScript

Inside Coach.createCriteria().list() among with other filters. This should return coach 372 but return empty:

JavaScript

Advertisement

Answer

I had to create a workaround with executeQuery where ids is the list containing the id’s of the coachproperties i was trying to fetch.

JavaScript
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement