在Grails中配置Postgres [英] Configuring Postgres in Grails

查看:102
本文介绍了在Grails中配置Postgres的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个迁移到MySQL和PostgreSQL的应用程序,并且我在数据分配时都有不同的行为。

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

通过分析在Postgres中创建的数据库,我意识到在每个表格中创建的ID的编号不会因另一个表格而发生更改。例如,它被设置在寄存器3'Table1'中,并将ID 1计数到3.当插入到另一个表中的另一个类的对象中时,应该为该表启动该ID,但是它遵循先前的序列并且当对象被保存在'table2'中时,他的第一个ID开始继续从4开始计数。我还注意到了Mysql中的一些变化,因为在'Postgres'中'false'字段'布尔'是preenchdio'0'假。

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 '.

我更新了JDBC,但问题仍然存在。我认为也许应该在该领域有一些'映射'的配置,但不确定。

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

我的DataSource是这样的:

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"
        }
    }
}

}

你可以遵循与PostgreSQL相同的模式吗?

You can follow the same pattern as in Mysql Postgres?

推荐答案

Postgres和Oracle中所有表的单一序列,但很容易为每个表创建一个序列。看到这个解决方案: http://grails.1312388.n4.nabble.com/One-hibernate-sequence-is-used-for-all-Postgres-tables-td1351722.html#a1351725

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

要使用自定义方言,请在src / groovy或src / java中创建类。使用任何你想要的包和类名。要在Grails中注册它,请在 DataSource.groovy中的 dataSource 块中设置 dialect 属性,例如

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 = ...
}

这篇关于在Grails中配置Postgres的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆