Details
-
Type:
Bug
-
Status:
Closed
-
Priority:
Major
-
Resolution: Fixed
-
Affects Version/s: 2.0-RC1
-
Fix Version/s: 2.0-RC3
-
Component/s: Persistence
-
Labels:
-
Environment:Win 7 (64) Java 6_0_29 (64), Grails 2.0.0.BUILD-SNAPSHOT as of 11/22/11
-
Source ID:
Description
This is a follow up of http://jira.grails.org/browse/GRAILS-8206
When totalCount is invoked on a result set, there is an additional "order by lower" in the generated "select count
" query if there is a "sort 'property'" in the domain class' mapping section, e.g.
static mapping
-
Hide
- totalCountIssue.zip
- 29/Nov/11 8:10 PM
- 632 kB
- Fat Zopilot
-
- totalCountIssue/.classpath 4 kB
- totalCountIssue/.project 0.9 kB
- totalCountIssue/.../com.springsource.sts.grails.core.prefs 0.2 kB
- totalCountIssue/.../org.codehaus.groovy.eclipse.preferences.prefs 0.1 kB
- totalCountIssue/.../org.eclipse.core.resources.prefs 1 kB
- totalCountIssue/.../org.eclipse.wst.common.project.facet.core.xml 0.1 kB
- totalCountIssue/application.properties 0.3 kB
- totalCountIssue/.../ApplicationResources.groovy 0.1 kB
- totalCountIssue/.../BootStrap.groovy 0.2 kB
- totalCountIssue/.../BuildConfig.groovy 2 kB
- totalCountIssue/grails-app/.../Config.groovy 4 kB
- totalCountIssue/.../DataSource.groovy 1 kB
- totalCountIssue/.../resources.groovy 0.0 kB
- totalCountIssue/.../UrlMappings.groovy 0.2 kB
- totalCountIssue/.../SomeDomainClass.groovy 0.2 kB
- totalCountIssue/.../messages.properties 3 kB
- totalCountIssue/.../messages_cs_CZ.properties 3 kB
- totalCountIssue/.../messages_da.properties 3 kB
- totalCountIssue/.../messages_de.properties 4 kB
- totalCountIssue/.../messages_es.properties 3 kB
- totalCountIssue/.../messages_fr.properties 2 kB
- totalCountIssue/.../messages_it.properties 2 kB
- totalCountIssue/.../messages_ja.properties 4 kB
- totalCountIssue/.../messages_nl.properties 3 kB
- totalCountIssue/.../messages_pt_BR.properties 3 kB
- totalCountIssue/.../messages_pt_PT.properties 3 kB
- totalCountIssue/.../messages_ru.properties 4 kB
- totalCountIssue/.../messages_sv.properties 3 kB
- totalCountIssue/.../messages_th.properties 6 kB
- totalCountIssue/.../messages_zh_CN.properties 2 kB
Issue Links
- is duplicated by
-
GRAILS-8390
totalCount throws error when order is specified
-
- is related to
-
GRAILS-8206
totalCount is broken
-
-
GRAILS-8380
Automatically disable order by clause for count() with where/named queries
-
Activity
- All
- Comments
- Work Log
- History
- Activity
- Git Commits
Well, the following produces invalid SQL using totalCount (at least Postgres says so; there is no problem with the in-memory DB).
class SomeDomainClass {
String company;
static constraints = {
}
static mapping =
{ sort "company" }}
class SomeService {
def serviceMethod()
{ def result = SomeDomainClass.list(offset : 0, max : 10); // assert result instanceof PagedResultList; log.info("Number of entities: "+result.totalCount); }}
This is the SQL produced: select count
as y0_ from some_domain_class this_ order by lower(this_.company) asc
and this is the error that is raised by Postgres:
ERROR: column "this_.company" must appear in the GROUP BY clause or be used in an aggregate function.
Postgres is known to be more strict than others regarding clean SQL ....
To reproduce:
Put PSQL JDBC driver in lib
Create sa user without pwd
create DB named g2
run-app (the demo project as uploaded)