0

I have been trying for this. But don't know it is possible or not. I need to list records by writing a crieria query on super class with conditions on subclass.

Say, Cats, Dogs extends Animal class. I need to list all animals but dogs with black dots and cats with white color. Here the key problem is, dog's properties are not in cat domain class.

But i have to write createCriteria on Animal class so that i can paginate with all animals or am i missing something?.

CSR
  • 770
  • 1
  • 14
  • 30

1 Answers1

0

given that you use tablePerHierarchy = true you should be able to write a native SQL query to select the records from the table by where-clauses pointing to partially null-ed columns:

Anumal.withCriteria{
  or{
    sqlRestriction "dots is not null and dots != 'black'" // dogs
    sqlRestriction "color = 'white'" // cats
  }
}
injecteer
  • 20,038
  • 4
  • 45
  • 89
  • 1
    is it not possible with out tablePerHierarchy=true because of which some properties in sub classes needs to be null – CSR Sep 18 '14 at 11:13