【问题标题】:How to set the transaction isolation level of a Postgres Datasource如何设置 Postgres 数据源的事务隔离级别
【发布时间】:2010-06-07 14:59:36
【问题描述】:

如何为 postgres 数据源设置全局事务隔离级别。

我在 jboss 上运行,我正在使用 hibernate 进行连接。

我知道我可以从休眠中设置隔离级别,这对 Postgres 有效吗?

这可以通过将 hibernate.connection.isolation hibernate 属性设置为 1,2,4,8 - 相关静态字段的各种值。

我正在使用 org.postgresql.xa.PGXADataSource

【问题讨论】:

    标签: java postgresql transactions java-ee-5


    【解决方案1】:

    如果你不使用 Hibernate 或者只是喜欢在数据源中设置隔离级别,所有 JBoss 数据源都支持<transaction-isolation> 标签:

    <datasources>
      <local-tx-datasource>
        <jndi-name>GenericDS</jndi-name>
        <connection-url>[jdbc: url for use with Driver class]</connection-url>
        <driver-class>[fully qualified class name of java.sql.Driver implementation]</driver-class>
        <user-name>x</user-name>
        <password>y</password>
        <!-- you can include connection properties that will get passed in 
         the DriverManager.getConnection(props) call-->
        <!-- look at your Driver docs to see what these might be -->
        <connection-property name="char.encoding">UTF-8</connection-property>
        <transaction-isolation>TRANSACTION_SERIALIZABLE</transaction-isolation>
        [...]
    

    我从JBoss wiki得到这个信息

    【讨论】:

      【解决方案2】:

      您可以通过这种方式设置隔离级别。 Hibernate 允许您以与数据库无关的方式执行此操作,因此它可以与 PostgreSQL 一起使用。

      【讨论】:

      • Hibernate In Action 一书中提到:“Hibernate 永远不会更改从托管环境中的应用程序服务器提供的数据源获得的连接的隔离级别。”正如 Alexander T 所回答的那样,您最好在 JBoss 的 DS 配置中设置隔离级别。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-11-20
      • 1970-01-01
      • 1970-01-01
      • 2011-12-17
      • 1970-01-01
      • 2012-04-22
      相关资源
      最近更新 更多