waveaccess opened a new issue, #14665:
URL: https://github.com/apache/grails-core/issues/14665

   I have a hierarchy with STI:
   
   ``` groovy
   class Entity {
      static namedQueries = {
          notDeleted {
          }
      }
   
   class ConcreteEntity extends Entity {
   }
   ```
   
   When I'm calling `ConcreteEntity.notDeleted.list()` it returns both `Entity` 
and `ConcreteEntity` instances, but when I'm calling 
`ConcreteEntity.findAllWhere(...)` it returns only `ConcreteEntity` instances 
as expected.
   
   I did some investigation for this problem (Grails 2.5.1, 
grails-datastore-gorm-hibernate-core 3.1.5) and found it adds named query 
methods for `ConcreteEntity` twice. First time in right context (domainClass == 
ConcreteEntiy) when it collecting all `namedQueries` closures from current 
Entity and its hierarchy. Second time in wrong context (domainClass == 
ConcreteEntity), when collecting `classesToAugment` in 
HibernateNamedQueriesBuilder. It adds the domainClass itself and all sub 
classes (including `ConcreteEntity`). So it overwrites 
ConcreteEntity.notDeleted method with closure for `ConcreteEntity` with new 
closure for `Entity`.
   
   I monkey patched with `metaClass` method from `HibernateNamedQueriesBuilder` 
and now it works as expected:
   
   ``` groovy
   HibernateNamedQueriesBuilder.metaClass.getClassesToAugment = {
     return [domainClass]
   }
   ```
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to