title: Grails 3 Oracle AssertionFailure on Save action with getGeneratedKeys support not enabled
body: <p>Problem: Error 500: Internal Server Error</p>
  
  <pre><code>URI: /listing/save
  Class: org.hibernate.AssertionFailure
  Message: getGeneratedKeys() support is not enabled
  </code></pre>
  
  <p>Configuration</p>
  
  <ul>
  <li>Environment: development</li>
  <li>App profile: web</li>
  <li>App version: 0.1</li>
  <li>Grails version: 3.0.1</li>
  <li>Groovy version: 2.4.3</li>
  <li>JVM version: 1.8.0_45 (64-bit)</li>
  <li>Reloading active: true</li>
  </ul>
  
  <p>Available Controllers:</p>
  
  <ul>
  <li>phonebook.ListingController</li>
  </ul>
  
  <p>Operating System: Windows 7
  Database: Oracle 11g R2 Enterprise Edition (11.2.0.4 64-bit)</p>
  
  <p>Debug output contains:</p>
  
  <pre><code>Grails application running at http://localhost:8080
  ERROR org.hibernate.AssertionFailure - HHH000099: an assertion failure occured (this may indicate a bug in Hibernate, but is more likely due to unsafe use of the session):     org.hibernate.AssertionFailure: getGeneratedKeys() support is not enabled
  ERROR org.grails.web.errors.GrailsExceptionResolver - AssertionFailure occurred when processing request: [POST] /listing/save - parameters:
  name: Scott
  phone: 555-1212
  create: Create
  getGeneratedKeys() support is not enabled. Stacktrace follows:
  org.hibernate.AssertionFailure: getGeneratedKeys() support is not enabled
      at phonebook.ListingController.$tt__save(ListingController.groovy:38) ~[main/:na]
      at grails.transaction.GrailsTransactionTemplate$2.doInTransaction(GrailsTransactionTemplate.groovy:93) ~[grails-core-3.0.1.jar:3.0.1]
      at grails.transaction.GrailsTransactionTemplate.execute(GrailsTransactionTemplate.groovy:90) ~[grails-core-3.0.1.jar:3.0.1]
      at grails.transaction.GrailsTransactionTemplate$2.doInTransaction(GrailsTransactionTemplate.groovy:93) ~[grails-core-3.0.1.jar:3.0.1]
      at grails.transaction.GrailsTransactionTemplate.execute(GrailsTransactionTemplate.groovy:90) ~[grails-core-3.0.1.jar:3.0.1]
      at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) ~[na:1.8.0_45]
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) ~[na:1.8.0_45]
      at java.lang.Thread.run(Thread.java:745) [na:1.8.0_45]
  
  File: grails-app\controllers\phonebook\ListingController
  Line: 38
  Content:         listing.save flush:true
  </code></pre>
  
  <p>Reproducing problem:</p>
  
  <ul>
  <li>C:\Dev> grails create-app phonebook</li>
  <li>C:\Dev> cd phonebook</li>
  </ul>
  
  <p>Edit: build.gradle</p>
  
  <pre><code>dependencies {
    ...
    runtime "com.oracle:jdbc-lib-ojdbc6:11.2.0.4"
    ...
  }
  </code></pre>
  
  <p>Note: Oracle client ojdbc6.jar added to local Maven repository at the coordinates specified above.</p>
  
  <p>Edit: grails-app\conf\application.yml</p>
  
  <pre><code>...
  dataSource:
      pooled: true
      jmxExport: true
      driverClassName: oracle.jdbc.OracleDriver
      username: scott
      password: tiger
  
  environments:
      development:
          dataSource:
              dbCreate: update
              url: jdbc:oracle:thin:@localhost:1521/sbx1
  ...
  </code></pre>
  
  <p>C:\Dev\phonebook> grails create-domain-class phonebook.listing
  Edit:grails-app\domain\phonebook\Listing.groovy</p>
  
  <pre><code>package phonebook
  
  class Listing {
      String name
      String phone
  
      static constraints = {
          name maxSize: 50
          phone maxSize: 14
      }
  }
  
  C:\Dev\phonebook&gt; grails generate-all phonebook.listing
  C:\Dev\phonebook&gt; grails run-app
  </code></pre>
  
  <p>The following confirms that the application connected to the database and created the table successfully:</p>
  
  <pre><code>SQL&gt; describe listing
   Name                                      Null?    Type
   ----------------------------------------- -------- ----------------------------
   ID                                        NOT NULL NUMBER(19)
   VERSION                                   NOT NULL NUMBER(19)
   NAME                                      NOT NULL VARCHAR2(50 CHAR)
   PHONE                                     NOT NULL VARCHAR2(14 CHAR)
  </code></pre>
  
  <p>There are also two sequences created in the schema:</p>
  
  <pre><code>HIBERNATE_SEQUENCE
  LISTING_SEQ
  </code></pre>
  
  <p>Note: These must have been created as a result at my many attempts to modify mapping attributes in the domain class for ID generation.</p>
  
  <p>Action once embedded Tomcat server is running on <a href="http://localhost:8080/" rel="nofollow">http://localhost:8080/</a>
  Internet Explorer: <a href="http://localhost:8080/" rel="nofollow">http://localhost:8080/</a>
  Click on link: Available Controllers > phonebook.ListingController
  Click on: New Listing
  Complete form and click: Create
  Result: Grails exception described above</p>
  
  <p>Research and troubleshooting activities:</p>
  
  <ul>
  <li>Problem not present is only change is Oracle to H2/HSQL file/memory database</li>
  <li>Discovered hibernate.jdbc.use_get_generated_keys setting but was unsuccessful in resolving issue by placing setting of true in application.yml configuration file</li>
  <li>Found multiple references to settings in grails-app/conf/DataSource.groovy but this is Grails 3 which uses application.yml</li>
  <li>Attempted multiple attributes in domain class for mapping ID column using generators</li>
  <li>Found little to no information in Grails 3 documentation covering this topic</li>
  <li>Hibernate documentation covers configuration settings and ID generators but does not provide Grails / Groovy application of that information</li>
  <li>Hibernate documentation states that not explicitly setting hibernate.jdbc.use_get_generated_keys results in it being set automatically by jdbc connection database metadata</li>
  </ul>
  
  <p>I attempted to resolve the problem by the following section in grails-app\conf\application.yml:</p>
  
  <pre><code>hibernate:
      jdbc:
          use_get_generated_keys: true
      cache:
          queries: false
  ...
  </code></pre>
  
  <p>I suspect that the resolution involves specific settings in grails-app\conf\application.yml but have not discovered the correct combination of configuration settings.</p>