persistence@glassfish.java.net

Re: entity manager flush problem

From: Oleg Mayevskiy <mayevskiy_at_spendino.de>
Date: Fri, 06 Aug 2010 21:10:11 +0200

I am watching database statement logs, also tables that should be filled
with new data. Additional i see all statements produced by hibernate in
java logs, because of hibernate.show_sql property.

Am 06.08.2010 20:58, schrieb Marina Vatkina:
> Hi Oleg,
>
> How do you check that nothing is flushed to the database?
>
> -marina
>
> Oleg Mayevskiy wrote:
>> Hi.
>>
>> I have a question about a following abstract problem.
>>
>> i have a stateless bean like this:
>>
>> @Stateless
>>
>> Public class MyBean implements MyLocalInterface {
>>
>> ….
>>
>> @PersistenceContext(unitName = "ReadWritePU")
>> private EntityManager em;
>>
>> ….
>>
>> @Override
>>
>> public void execute() {
>>
>> …
>>
>> em.find(…) (some finds)
>>
>> …
>>
>> em.merge(…) (some merges)
>>
>> …
>>
>> em.persist(…) (some persists)
>>
>> }
>>
>> but what happens on db is:
>>
>> BEGIN
>> some SELECTs(from some finds)
>> ....
>> COMMIT
>>
>> so what happens is, entity manager does not flush the objects from
>> merge and persist methods, no updates or inserts are done to the
>> database. Also no Runtime Exceptions are thrown.
>>
>> But if i put an em.flush() at the end of the business method, every
>> thing is ok and new objects are flushed to the db.
>>
>> What could be a reason for this behavior?
>>
>> I tried to change non-transactional-connections from false to true,
>> the transaction-isolation-level from serializable to read-commited
>> and is-isolation-level-guaranteed from true to false, but it did not
>> help.
>>
>>
>> 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/persistence
>> http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
>> <http://java.sun.com/xml/ns/persistencehttp:/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="false" 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>
>>
>>
>> Thank you very much
>>
>> Oleg Mayevskiy