How-to: Grails 3.0.2 + Oracle Database 12c?

后端 未结 4 530
名媛妹妹
名媛妹妹 2021-01-13 13:53

I am making my first steps with Grails and try to create a hello world application with an Oracle Database 12c.

Unfortunately the tutorial documentation on the datab

相关标签:
4条回答
  • 2021-01-13 14:36

    Hibernate as of 2.0.1 (Grails 2.0.1) supported a property "dialect". As shown below. Presume there's a similar property still for newer versions of Hibernate.

    File .../grails-app/conf/DataSource.groovy

    // Global data source settings
    // Note that these global properties values are composited with
    // the environment-specific properties under "environments"
    dataSource {
      pooled = true
      driverClassName = "oracle.jdbc.OracleDriver"
      ...
      // Required for function with Oracle 12c and above.
      // Not required for Oracle 11.2 and below. For the present works with both.
      // Specifying Oracle 10 dialect is sufficient.
      // Oracle 12c specific dialect support is not available for Hibernate 2.0.1.
      // Works with either ojdbc7 or ojdbc8 jars.
      dialect = org.hibernate.dialect.Oracle10gDialect
    }
    

    Applying the "dialect" property was sufficient to run older code against both Oracle 11g, 12c. It bought time for code migration to newer versions and dependencies.

    0 讨论(0)
  • 2021-01-13 14:40

    yes this will be OK for meanwhile. But there are details missing. I'll post detailed instructions as soon as i get to the office. Actually there is a sample for mySql somewhere on the grails site, and from it it's pretty clear how to make same for an oracle DB.

    I just have created a new app and compared it with myne for oracle 11g. Here it is:

    1. ./build.gradle, add following line to "dependencies" section:

      runtime "com.oracle:ojdbc14:10.2.0.3.0"

    2. ./grails-app/conf/application.yml, add following to "hibernate" section:

    jdbc:
        use_get_generated_keys: true
    
    1. ./grails-app/conf/application.yml, dataSource: section should be like:
    dataSource:
        pooled: true
        jmxExport: true
        driverClassName: oracle.jdbc.OracleDriver
        username: YOURUSERNAME
        password: yoursecret
    
    1. ./grails-app/conf/application.yml, environments: configuration, all three environments should be like:
    environments:
    development:
        dataSource:
            dbCreate: create
            url: jdbc:oracle:thin:@somehost.net:1521:YOURORAINSTANCE
    test:
        dataSource:
            dbCreate: update
            url: jdbc:oracle:thin:@somehost.net:1521:YOURORAINSTANCE
    production:
        dataSource:
            dbCreate: update
            url: jdbc:oracle:thin:@somehost.net:1521:YOURORAINSTANCE
    

    And the Hibernate dialect for Oracle you have is pretty old one, I think you'd better remove it, without specifying it explicitly all works fine.

    0 讨论(0)
  • 2021-01-13 14:46
    1. download ojdbc7.jar from http://www.oracle.com/technetwork/database/features/jdbc/jdbc-drivers-12c-download-1958347.html

    2. create a <myapp>/lib folder in the main folder of your application (lib folder was removed from Grails 3)

    3. copy ojdbc7.jar to lib folder

    4. add this line to the <myapp>/build.gradle file

      dependencies{
           (...)
           runtime fileTree(dir: 'lib', include: '*.jar')
           (...)
      }
    
    1. create lines in the <myapp>/grails-app/conf/application.yml
     hibernate:
          (...)
          jdbc:
             use_get_generated_keys: true
    
     dataSource:
        pooled: true
        jmxExport: true
        driverClassName: oracle.jdbc.OracleDriver
        username: DBUSERNAME
        password: dbpassword
    
     environments:
         development:
             dataSource:
                 dbCreate: create
                 url: jdbc:oracle:thin:@localhost.net:1521:dbname
         test:
             dataSource:
                 dbCreate: update
                 url: jdbc:oracle:thin:@localhost.net:1521:dbname
         production:
             dataSource:
                 dbCreate: update
                 url: jdbc:oracle:thin:@locaLhost.net:1521:dbname
    
    0 讨论(0)
  • 2021-01-13 14:49

    You can get the JDBC driver through this maven command.

    mvn install:install-file \ -Dfile=/lib/ojdbc7.jar \ -DgroupId=com.oracle \ -DartifactId=ojdbc7 \ -Dversion=12.1.0.1 \ -Dpackaging=jar \ -DgeneratePom=true

    0 讨论(0)
提交回复
热议问题