Configuring Postgres in Grails

本小妞迷上赌 提交于 2020-01-02 10:59:14

问题


I have an application in migrating to MySQL and PostgreSQL and I both have different behaviors in the allocation of data.

By analyzing the database created in Postgres, I realized that the numbering of ID's created in each table are not being reset in change for another table. For example, it was set in the registers 3 'Table1' and counting the ID 1 to 3. When inserted into an object of another class in another table, the ID should be started for that table, but it follows the sequence of previous and when the object is persisted in 'table2' instead his first start with the ID continues to count from 4. I also noticed some changes in Mysql as the 'false' field 'boolean' is preenchdio with '0 'in Postgres is filled with' false '.

I updated the JDBC but the problem continues. I think maybe there should be some configuration of 'mapping' in the field, but not sure.

My DataSource is thus:

environments {
development {
    dataSource {

        dbCreate = "update" // one of 'create', 'create-drop', 'update', 'validate', ''

    url = "jdbc:postgresql://localhost:5432/app"
        driverClassName = "org.postgresql.Driver"
        dialect = org.hibernate.dialect.PostgreSQLDialect
        //url = "jdbc:mysql://localhost:3306/app"
        username = "app"
        password = "app123"

    }
}
test {
    dataSource {
        dbCreate = "update"
        url = "jdbc:h2:mem:testDb;MVCC=TRUE;LOCK_TIMEOUT=10000"
        username = "sa"
        password = ""
    }
}
production {
    dataSource {
        dbCreate = "update"
        url = "jdbc:postgresql://localhost:5432/app"
        driverClassName = "org.postgresql.Driver"
        username = "postgres"


        pooled = true
        properties {
           maxActive = -1
           minEvictableIdleTimeMillis=1800000
           timeBetweenEvictionRunsMillis=1800000
           numTestsPerEvictionRun=3
           testOnBorrow=true
           testWhileIdle=true
           testOnReturn=true
           validationQuery="SELECT 1"
        }
    }
}

}

You can follow the same pattern as in Mysql Postgres?


回答1:


Hibernate creates a single sequence for all tables in both Postgres and Oracle, but it's easy to create a single sequence per table. See this solution: http://grails.1312388.n4.nabble.com/One-hibernate-sequence-is-used-for-all-Postgres-tables-td1351722.html#a1351725

To use the custom dialect, create the class in src/groovy or src/java. Use whatever package and class name you want. To register it in Grails, set the dialect property in the dataSource block in DataSource.groovy, e.g.

dataSource {
   pooled = true
   dialect = com.foo.bar.MyDialect
   driverClassName = ...
   username = ...
   password = ...
}


来源:https://stackoverflow.com/questions/12850955/configuring-postgres-in-grails

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!