persistence@glassfish.java.net

AW: Container managed transactions commiting problem

From: Oleg Mayevskiy <mayevskiy_at_spendino.de>
Date: Tue, 3 Aug 2010 18:10:22 +0200

In this case i do not override TransactionAttribute, so it is set to default
which is REQUIRES.

But I also tried to mark the method with
@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)

 

The behavior remains the same, no db transaction is started.

 

Von: Mitesh Meswani [mailto:mitesh.meswani_at_oracle.com]
Gesendet: Dienstag, 3. August 2010 18:06
An: persistence_at_glassfish.dev.java.net
Betreff: Re: Container managed transactions commiting problem

 

Are you overriding transaction attribute for execute() externally or is is
the default (REQUIRES) ?

  
On 8/3/2010 8:55 AM, 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>
"http://java.sun.com/xml/ns/persistence" xmlns:xsi=
<http://www.w3.org/2001/XMLSchema-instance>
"http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation=
<http://java.sun.com/xml/ns/persistencehttp:/java.sun.com/xml/ns/persistence
/persistence_1_0.xsd> "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