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

   Dear Grails developer team,
   
   I would like to report the following issue: When running a dynamic 
countByDynamicStuffBlah on a static where query of a domain class, the where 
code is not transformed into SQL properly. However running the same on a named 
query instead of a where query OR running a findByDynamicStuffBlah on the where 
query works correctly.
   
   FYI: I have re-filed the issue in this tracker because it is rather a 
Gorm/Hibernate issue than a grails-core issue.
   ### Steps to Reproduce
   1. Download the example application: 
[countby.zip](https://github.com/grails/gorm-hibernate5/files/476300/countby.zip)
   2. Unpack the zip archive somewhere
   3. Go to the new folder "countby"
   4. If you use gvm, type: `gvm use grails 3.2.0.RC1`
   5. Type: `grails run-app`
   6. Browse to http://localhost:8080/
   7. Open the following files: Bootstrap.groovy (puts together the test 
files),  Book.groovy (the Book domain class with a where query and a named 
query), BookController.groovy (executes the tests and shows the results via 
println() )
   8. Select the Book controller in the UI (book/index)
   9. Watch the grails log and compare it to my attached log.txt
   ### Expected Behaviour
   
   countBy should work the same way as findBy on where queries, so if findBy 
returns 2 objects, so should countBy.
   ### Actual Behaviour
   
   countByAuthor works with the named query, however not with the where query. 
logSql is set to true in the project, so you can see that the named query 
generates "this_.is_scientific=? and this_.author_id=?", whereas 
"this_.is_scientific=?" is omitted in the where query.
   
   Here is the log i got on my machine: 
[log.txt](https://github.com/grails/gorm-hibernate5/files/476301/log.txt)
   
   Have a look at the SQL statements on these lines:
   - 49: findByAuthor  on **where query** => is_scientific condition **PRESENT**
   - 52: findByAuthor on **named query** => is_scientific condition **PRESENT**
   - 55: countByAuthor on **where query** => is_scientific condition **MISSING**
   - 58: countByAuthor on **named query** => is_scientific condition **PRESENT**
   ### Environment Information
   - **Operating System**:
     myuser@mybox:~$ cat /etc/issue
     Ubuntu 16.04.1 LTS \n \l
     myuser@mybox:~$ uname -a
     Linux mybox 4.4.0-36-generic grails/grails-data-mapping#2009-Ubuntu SMP 
Thu Aug 11 18:01:55 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux
   - **Grails Version:**
     myuser@mybox:~$ grails -v
     Java HotSpot(TM) 64-Bit Server VM warning: ignoring option 
MaxPermSize=1024m; support was removed in 8.0
     | Grails Version: 3.2.0.RC1
     | Groovy Version: 2.4.7
     | JVM Version: 1.8.0_101
   - **JDK Version:**
     myuser@mybox:~$ java -version
     java version "1.8.0_101"
     Java(TM) SE Runtime Environment (build 1.8.0_101-b13)
     Java HotSpot(TM) 64-Bit Server VM (build 25.101-b13, mixed mode)
   ### Example Application
   - see zip file with example application
   ### Futher facts
   - It all still worked in Grails 2.5.0 with hibernate4
   - The same error happens with PostgreSQL databases, not just h2
   
   Thank you in advance for having a look at this issue!
   


-- 
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