persistence@glassfish.java.net

Re: Container managed transactions commiting problem

From: Marina Vatkina <marina.vatkina_at_oracle.com>
Date: Tue, 03 Aug 2010 09:33:42 -0700

Your resource marked non-transactional-connections="true". This means
you do not want your connections participate in a transaction.

Check also that transaction-isolation-level="serializable" setting is
what you want.

Best,
-marina

Oleg Mayevskiy wrote:
>
> Hi.
>
> At first, my core problem is:
>
> e.g. I have an ejb method inside a stateless bean
>
> @Stateless
>
> Public class MyBean implements MyLocalInterface {
>
> ….
>
> @PersistenceContext(unitName = "ReadWritePU")
>
> private EntityManager em;
>
> ….
>
> @Override
>
> public void execute() {
>
> …
>
> em.find(…)
>
> …
>
> em.merge(…)
>
> …
>
> em.persist(…)
>
> }
>
> Well what happens on the database side is:
>
> Select …..
>
> Update ….
>
> Insert ….
>
> But what I am expecting on database side is:
>
> BEGIN;
>
> Select …..
>
> Update ….
>
> Insert ….
>
> COMMIT;
>
> That is, I want all statements produced inside one ejb method are also
> inside a single database transaction.
>
> Here some more infos about my environment:
>
> debian
>
> Glassfish v2.1
>
> PostgreSQL 8.3
>
> Hibernate 3
>
> Here is my whole persistence.xml
>
> <?xml version="1.0" encoding="UTF-8"?>
>
> <persistence version="1.0"
> xmlns="http://java.sun.com/xml/ns/persistence"
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
> http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">
>
> <persistence-unit name="ReadWritePU" transaction-type="JTA">
>
> <provider>org.hibernate.ejb.HibernatePersistence</provider>
>
> <jta-data-source>jdbc/Postgres</jta-data-source>
>
> <exclude-unlisted-classes>false</exclude-unlisted-classes>
>
> <properties>
>
> <property name="hibernate.show_sql" value="true"/>
>
> <property name="hibernate.dialect"
> value="org.hibernate.dialect.PostgreSQLDialect"/>
>
> <property name="hibernate.order_updates" value="true"/>
>
> <property name="hibernate.transaction.manager_lookup_class"
> value="org.hibernate.transaction.SunONETransactionManagerLookup"/>
>
> <property name="hibernate.transaction.factory_class"
> value="org.hibernate.transaction.CMTTransactionFactory"/>
>
> </properties>
>
> </persistence-unit>
>
> <persistence-unit name="ReadOnlyPU" transaction-type="JTA">
>
> <provider>org.hibernate.ejb.HibernatePersistence</provider>
>
> <jta-data-source>jdbc/PostgresReadonly</jta-data-source>
>
> <exclude-unlisted-classes>false</exclude-unlisted-classes>
>
> <properties>
>
> <property name="hibernate.dialect"
> value="org.hibernate.dialect.PostgreSQLDialect"/>
>
> <property name="hibernate.show_sql" value="true"/>
>
> <property name="hibernate.transaction.manager_lookup_class"
> value="org.hibernate.transaction.SunONETransactionManagerLookup"/>
>
> <property name="hibernate.transaction.factory_class"
> value="org.hibernate.transaction.CMTTransactionFactory"/>
>
> </properties>
>
> </persistence-unit>
>
> </persistence>
>
> And here are my connection pool settings from the domain.xml
>
> <jdbc-connection-pool allow-non-component-callers="true"
> associate-with-thread="false" connection-creation-retry-attempts="0"
> connection-creation-retry-interval-in-seconds="10"
> connection-leak-reclaim="false" connection-leak-timeout-in-seconds="0"
> connection-validation-method="table"
> datasource-classname="org.postgresql.ds.PGConnectionPoolDataSource"
> fail-all-connections="false" idle-timeout-in-seconds="300"
> is-connection-validation-required="true"
> is-isolation-level-guaranteed="true"
> lazy-connection-association="false" lazy-connection-enlistment="false"
> match-connections="false" max-connection-usage-count="0"
> max-pool-size="32" max-wait-time-in-millis="60000"
> name="PostgresConnectionPool" non-transactional-connections="true"
> pool-resize-quantity="2" res-type="javax.sql.ConnectionPoolDataSource"
> statement-timeout-in-seconds="-1" steady-pool-size="8"
> transaction-isolation-level="serializable"
> validate-atmost-once-period-in-seconds="0"
> validation-table-name="pg_type" wrap-jdbc-objects="false">
>
> <property name="Password" value="********"/>
>
> <property name="PrepareThreshold" value="0"/>
>
> <property name="ServerName" value="******"/>
>
> <property name="DatabaseName" value="*****"/>
>
> <property name="LoginTimeout" value="0"/>
>
> <property name="User" value="*********"/>
>
> <property name="PortNumber" value="*******"/>
>
> <property name="Ssl" value="true"/>
>
> <property name="sslfactory"
> value="org.postgresql.ssl.NonValidatingFactory"/>
>
> </jdbc-connection-pool>
>
> If you need more info about my inviroment pls tell me.
>
> Many Thanx
>
> Oleg Mayevskiy
>