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

时间:2010-06-07 14:59:36

标签: java postgresql transactions java-ee-5

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

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

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

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

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

2 个答案:

答案 0 :(得分:4)

如果您没有使用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

获得了这些信息

答案 1 :(得分:1)

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