3 Posts Found

Enable Hibernate SQL Logging in Grails

Posted: 5/18/2017 6:08 PM

It's often useful when debugging a Grails application to be able to see the exact SQL that is being executed in the database.

If you're using GORM, you can modify your /grails-app/conf/application.yml file with the following settings. Each Hibernate statement that is executed will be outputted to the standard console.

    logSql: true
    formatSql: true

Hibernate Error: @P0 Syntax Error

Posted: 5/18/2017 6:02 PM

Grails domain classes using GORM offer the dynamic finders Class.findByXXX() and Class.findAllByXXX(max: 123), which will retrieve 1 record and 123 records, respectively.

On SQL Server 2012 or higher, attempting to call one of these functions will throw a Hibernate error "Invalid syntax @p0". This is because you need to add an additional configuration option to your /grails-app/conf/application.yml file dataSource section:

dialect: org.hibernate.dialect.SQLServer2012Dialect

Default Grails GORM Domain Class Failures to Display

Posted: 11/29/2016 3:49 PM

By default, when a GORM .save() function call fails, it fails silently. If you want it to always throw an error, add this to your /grails-app/conf/application.yml file at the bottom.

    failOnError: true