Grails 2.4 and hibernate4 errors with run-app

前端 未结 3 955
感情败类
感情败类 2020-11-29 07:35

I\'ve upgraded an app to Grails 2.4.0, and I\'m using the hibernate4 plugin. When executing run-app the error examples below are generated for each domain class using the in

相关标签:
3条回答
  • 2020-11-29 07:54

    The Solution @Luis provided above works for MYSQL too. Just extend MySQL5InnoDBDialect instead like below:

    import org.hibernate.dialect.MySQL5InnoDBDialect;
    
    public class ImprovedMySQLDialect extends MySQL5InnoDBDialect {
        @Override
        public String getDropSequenceString(String sequenceName) {
            // Adding the "if exists" clause to avoid warnings
            return "drop sequence if exists " + sequenceName;
        }
    
        @Override
        public boolean dropConstraints() {
            // We don't need to drop constraints before dropping tables, that just leads to error
            // messages about missing tables when we don't have a schema in the database
            return false;
        }
    }
    

    Then in your datasource file change the following line:

    dialect = org.hibernate.dialect.MySQL5InnoDBDialect
    

    to

    dialect = my.package.name.ImprovedMySQLDialect
    
    0 讨论(0)
  • 2020-11-29 08:00

    It's a bug, it seems that you can leave it that way and will cause no problem, but if you don't want to see the message here are some solutions: (Edit: Option 2 seems to work better (see comments in this post))

    1.- singleSession configuration from DataSource.groovy

    https://jira.grails.org/browse/GRAILS-11198

    2.- overriding the H2 dialect:

    public class ImprovedH2Dialect extends H2Dialect {
        @Override
        public String getDropSequenceString(String sequenceName) {
            // Adding the "if exists" clause to avoid warnings
            return "drop sequence if exists " + sequenceName;
        }
    
        @Override
        public boolean dropConstraints() {
            // We don't need to drop constraints before dropping tables, that just
            // leads to error messages about missing tables when we don't have a
            // schema in the database
            return false;
        }
    }
    

    Unsuccessful: alter table XXX drop constraint YYY in Hibernate/JPA/HSQLDB standalone

    0 讨论(0)
  • 2020-11-29 08:16

    Just set dbCreate="update", and the errors go away immediately.

    The problem is that GORM (hibernate) is trying to drop tables in the H2 DB that have never been created because the DB is created new each time you run the app. Unfortunately, dbCreate is set to create-drop by default, which really doesn't make sense for a database that is created on the fly at runtime.

    development {
        dataSource {
            dbCreate = "update" // one of 'create', 'create-drop', 'update', 'validate', ''
            url = "jdbc:h2:mem:devDb;MVCC=TRUE;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE"
        }
    
    0 讨论(0)
提交回复
热议问题