0
votes

According to this tutorial I was configuring a simple grails application. It worked fine with the internal database that comes with grails. Then I was trying to connect an oracle database with the app but Im getting the following error.

Error 2015-10-06 14:21:37,774 [localhost-startStop-1] ERROR context.GrailsContextLoader - Error initializing the application: Error creating bean with name 'transactionManagerPostProcessor': Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager': Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory': Cannot resolve reference to bean 'hibernateProperties' while setting bean property 'hibernateProperties'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'hibernateProperties': Cannot resolve reference to bean 'dialectDetector' while setting bean property 'properties' with key [hibernate.dialect]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dialectDetector': Invocation of init method failed; nested exception is org.springframework.jdbc.support.MetaDataAccessException: Error while extracting DatabaseMetaData; nested exception is org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (Listener refused the connection with the following error: ORA-12505, TNS:listener does not currently know of SID given in connect descriptor ) Message: Error creating bean with name 'transactionManagerPostProcessor': Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager': Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory': Cannot resolve reference to bean 'hibernateProperties' while setting bean property 'hibernateProperties'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'hibernateProperties': Cannot resolve reference to bean 'dialectDetector' while setting bean property 'properties' with key [hibernate.dialect]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dialectDetector': Invocation of init method failed; nested exception is org.springframework.jdbc.support.MetaDataAccessException: Error while extracting DatabaseMetaData; nested exception is org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (Listener refused the connection with the following error: ORA-12505, TNS:listener does not currently know of SID given in connect descriptor

This is my DataSource.groovy file

dataSource {
    pooled = true
    driverClassName = "oracle.jdbc.OracleDriver"
    username = "system"
    password = "password"


}
hibernate {
    cache.use_second_level_cache = true
    cache.use_query_cache = false
    cache.region.factory_class = 'net.sf.ehcache.hibernate.EhCacheRegionFactory'
}
// environment specific settings
environments {
    development {
        dataSource {
            dbCreate = "update" // one of 'create', 'create-drop', 'update', 'validate', ''
            url = "jdbc:oracle:thin:@tan.example.com:1521:orcl;MVCC=TRUE;LOCK_TIMEOUT=10000"
        }
    }
    test {
        dataSource {
            dbCreate = "update"
            url = "jdbc:h2:mem:testDb;MVCC=TRUE;LOCK_TIMEOUT=10000"
        }
    }
    production {
        dataSource {
            dbCreate = "update"
            url = "jdbc:h2:prodDb;MVCC=TRUE;LOCK_TIMEOUT=10000"
            pooled = true
            properties {
               maxActive = -1
               minEvictableIdleTimeMillis=1800000
               timeBetweenEvictionRunsMillis=1800000
               numTestsPerEvictionRun=3
               testOnBorrow=true
               testWhileIdle=true
               testOnReturn=true
               validationQuery="SELECT 1"
            }
        }
    }
}

I already have the jdbc driver in the lib folder. Any idea what is wrong here? Thank you.

1
Shouldn't the url be: jdbc:oracle:thin:@tan.example.com:1521/orcl ?tim_yates
Tried it. Error says invalid formatnilan59
First try to connect to the database with sqlplus using this command - sqlplus system/password@orcl. If that works you'll know your DB is working fine and is accessible, and then we can continue to solve the problem in grails.Yaron Idan

1 Answers

0
votes

This works on my test server. TESTSERVER is of course the server name but could also be the IP address.

development {
    dataSource {
        pooled = true
        dialect = org.hibernate.dialect.Oracle11gDialect
        driverClassName = 'oracle.jdbc.OracleDriver'
        username = 'username' // YOUR USERNAME AND PASS
        password = 'password'
        url = 'jdbc:oracle:thin:@TESTSERVER:1521:TESTDB'
        dbCreate = 'update'

    }
}