Hi everyone, Upgrading from grails 2.3.4 to 2.5.6 ...
# questions
v
Hi everyone, Upgrading from grails 2.3.4 to 2.5.6 for MySQL 5.7 to 8.0 and Java 8. While using the hibernate 4 configuration, a Domain's table not present in target database (A) but in non target database (B or C) but app not throwing error. If I remove the table from B or C its throwing error. Same scenario observed in MySQL 5.7 and 8.0 for hibernate 4 configuration. For hibernate 3 and MySQL 5.7, getting error. Is it feasible to use MySQL 8.0 with grails 2.5.6? Any configuration need to updated? DataSource.groovy
Copy code
dataSource {
    pooled = true
    jmxExport = true
//    driverClassName = "com.mysql.jdbc.Driver" // MySQL 5.7
    driverClassName = "com.mysql.cj.jdbc.Driver" // MySQL 8.0
}
hibernate {
    cache.use_second_level_cache = false
    cache.use_query_cache = false
//    cache.region.factory_class = 'org.hibernate.cache.SingletonEhCacheRegionFactory' // MySQL 5.7
    cache.region.factory_class = 'org.hibernate.cache.ehcache.SingletonEhCacheRegionFactory' // MySQL 8.0
    singleSession = true // configure OSIV singleSession mode
    flush.mode = 'auto' // OSIV session flush mode outside of transactional context
}

// environment specific settings
environments {
    development {
        dataSource {
            dbCreate = "validate"
            url = "jdbc:<mysql://localhost:3306/learn_around?useUnicode=true&characterEncoding=utf8>" // MySQL 5.7
//            url = "jdbc:<mysql://localhost:3308/mig_learn_around?useUnicode=true&characterEncoding=utf8>" // MySQL 8.0
            username = "root"
            password = "ard5050"
        }
    }
}
BuildConfig.groovy
Copy code
dependencies {
        // <https://mvnrepository.com/artifact/mysql/mysql-connector-java>
        // runtime 'mysql:mysql-connector-java:5.1.49'
        runtime 'mysql:mysql-connector-java:8.0.33'
    }

    plugins {
//        runtime ":hibernate:3.6.10.18"
        runtime ":hibernate4:4.3.10"
    }
g
I would suggest to upgrade Grails first, then MySQL (or the opposite) so you can isolate issues easily. It happened to me that MySQL 8 had new keywords (respect to MySQL 5) mathing some field names in my tables causing exceptions. What exception are you getting?
v
Copy code
driverClassName = "com.mysql.jdbc.Driver" // MySQL 5.7

cache.region.factory_class = 'org.hibernate.cache.ehcache.EhCacheRegionFactory' // MySQL 5.7
@giangio As per you mentioned, I have kept the configuration as it pointing to 5.7 DB from Grails 2.5.6. DataSource.groovy
Copy code
driverClassName = "com.mysql.jdbc.Driver" // MySQL 5.7

cache.region.factory_class = 'org.hibernate.cache.ehcache.EhCacheRegionFactory' // MySQL 5.7

url = "jdbc:<mysql://localhost:3306/learn_around?useUnicode=true&characterEncoding=utf8>" // MySQL 5.7
BuildConfig.groovy
Copy code
runtime 'mysql:mysql-connector-java:5.1.29'


runtime ":hibernate4:4.3.10"
I am getting error that supposed occur:
Copy code
2024-04-03 21:59:51,382 [localhost-startStop-1] ERROR context.GrailsContextLoaderListener  - 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': Invocation of init method failed; nested exception is org.hibernate.HibernateException: Missing table: book
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': Invocation of init method failed; nested exception is org.hibernate.HibernateException: Missing table: book
But when I use the following connector
Copy code
runtime 'mysql:mysql-connector-java:8.0.33'
Getting this. The point is app started without the table book (Note that this table exists in a DB that not
learn_around
Copy code
Error |
Loading class `com.mysql.jdbc.Driver'. This is deprecated. The new driver class is `com.mysql.cj.jdbc.Driver'. The driver is automatically registered via the SPI and manual loading of the driver class is generally unnecessary.
|Server running. Browse to <http://localhost:8080/cl_migrate>
g
Have you tried to execute the gradle task "clean" before running the app?
v
Yes. I have tried both
grails clean
and
grails clean-all
a
@Veeramanikandan S, were you able to proceed on this? We also need to upgrade mysql from 5.7 to 8 and the grails is old 2.5.4. It would be helpful if you can share your inputs and research on this
v
BuildConfig.groovy
Copy code
dependencies {
    // specify dependencies here under either 'build', 'compile', 'runtime', 'test' or 'provided' scopes e.g.
    // <https://mvnrepository.com/artifact/mysql/mysql-connector-java>
    runtime 'mysql:mysql-connector-java:8.0.33'
}
    plugins {
//        runtime ":hibernate:3.6.10.19"
        runtime ":hibernate4:4.3.10"
}
DataSource.groovy
Copy code
dataSource {
    pooled = true
    jmxExport = true
    // Set the MySQL 8 driver class name
//    driverClassName = "com.mysql.jdbc.Driver"
    driverClassName = "com.mysql.cj.jdbc.Driver"

    // Set the dialect for MySQL 8
    // dialect = 'org.hibernate.dialect.MySQL8Dialect' #removed this because of Hibernate version bundled with Grails 2.5.6 does not recognize MySQL8Dialect as it predates MySQL 8.
    // The dialect below is compatible with MySQL 5.x and 8.x
    dialect = 'org.hibernate.dialect.MySQL5InnoDBDialect'

    //dialect = "com.domain.mysql.dialect.MySQLUTF8InnoDBDialect" for UTF-8 handling
    //dialect = "org.hibernate.dialect.MySQL5InnoDBDialect"
    //logSql = true
    //formatSql = true
}

hibernate {
    cache.use_second_level_cache = false // as per existing datasource.
    cache.use_query_cache = false
    // cache.region.factory_class = 'org.hibernate.cache.ehcache.EhCacheRegionFactory' // MySQL 5.7
    // cache.region.factory_class = 'org.hibernate.cache.SingletonEhCacheRegionFactory' // Hibernate 3
    cache.region.factory_class = 'org.hibernate.cache.ehcache.SingletonEhCacheRegionFactory' // Hibernate 4
    singleSession = true // configure OSIV singleSession mode
    flush.mode = 'auto' // OSIV session flush mode outside of transactional context
}
@Anuradha Bhan hope this helps.
a
@Veeramanikandan S, I will try this configuration and will update soon. Thank you !!
👍 1
Thank you @Veeramanikandan S, the solution worked !!
👍 1
v
You're welcome! I'm glad to hear that the solution worked for you!