English 中文(简体)
与协会的铁路“最大”分局,只接收最先进的水管
原标题:Grails "max" subquery with an association, to get only the latest of a hasMany

The simplified domain model: Txn (as in Transaction) hasMany TxnStatus . TxnStatus has a dateTime

这是一种遗产测绘,因此,我不得不改变银,在Txn进行测绘:

  static mapping = { 
    txnStatus column:  MessageID , ignoreNotFound: true, fetch:  join 
  }

我需要根据一些动态建筑标准获得Txns,目前使用GORM的电梯度,它运转良好;BUT I也需要只获得 最新txnStatus。

Tried:

def query = Txn.where {
   txnStatus { dateTime == max(dateTime) }    
}

引文:java.lang.ClassCastException: org.hibernate.criterion.DetalateCriteria不能被 j。 日期:

还审判:

 def query = Txn.where {
       txnStatus.dateTime == max(txnStatus.dateTime)    
    }

规定:

Compilation Error: ... 
            Cannot use aggregate function max on expressions "txnStatus.dateTime"

在现阶段,我想把任何帮助改为“总部”。

问题回答

几天前有一个问题非常类似。 看来,如果使用最高分局的查询,则与=

检察官办公室能够与它合作,并以此方式开展工作。 看看问点没有帮助我看一看。

这里确实是一个野心——

    Txn.where {
        txnStatus  {
          dateTime == property(dateTime).of { max(dateTime) }
        }
    }




相关问题
grails + gwt request handling via controllers

I am new to gwt. I am trying to integrate gwt+grails.Can anybody provide me a good example for handling the request using grails controllers and not a custom servlet.I will be really thankful if ...

Error loading the grails gwt module xml

I ve installed the plugin from this article by Peter http://www.cacoethes.co.uk/blog/groovyandgrails/the-command-pattern-w.... While compile time its not able to find the module file which is present ...

Sorting Objects Based on Custom Domain Class Methods

I have a domain class, in which I ve defined some methods which give the object a score based on different algorithms (eg. popularity). I now want to retrieve a list of these objects sorted by one of ...

Grails Packaging and Naming Conventions

Packaging Controllers, Services,etc. i.e. - com.company.controllers - com.company.services Is this a good practice or should be avoided by all means?? Another worth mentioning problem I encountered ...

Hibernate/GORM: collection was not processed by flush()

I have an integration test in my Grails application that fails when I try to save an entity of type Member invitingMember.save(flush: true) This raises the following exception org.hibernate....

热门标签