java - 如何设置 Postgres 数据源的事务隔离级别

标签 java postgresql transactions java-ee-5

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

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

我知道我可以设置 hibernate 隔离级别,这对 Postgres 有用吗?

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

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

最佳答案

如果您不使用 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 获得了这些信息

关于java - 如何设置 Postgres 数据源的事务隔离级别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2990571/

相关文章:

postgresql - 查询结构与函数结果类型不匹配,RETURNS TABLE

c++将没有时区的postgres时间戳转换为time_t

django - 使用 psycopg2 将 django 与 postgresql 连接起来

sql-server - 如何以编程方式在 SQL Server 中启用 READ COMMITTED SNAPSHOT?

java - 如何知道消息是否已被确认/确认?

重新选择文件时 Java JTree 卡住

java - 在 spring-boot 中为 Graphite 千分尺事件添加前缀

java - Spring独立应用程序的全局错误处理

performance - 处理大额交易: any time/memory tradeoffs?

PHP + MySQL 事务示例