FlushMode=MANUAL -- not immediately commited to db?
tynor Feb 7, 2008 1:28 PMSeam 2.0.0.GA
Hibernate 3.2.4.sp1
MySQL 5.0.16
I am using EJB3/JPA persistence and am having trouble with a manually flushed transaction. Even after a call to em.flush(), the data is not visible to an external db client -- it seems that even though manually flushed, the transaction is not committed until after the outer backing bean action method returns.
I need to ensure that my pending changes to the db are commited to the db so that I can invoke another application which uses that data from the database -- all before actually returning from the backing bean action.
I've tried to call em.getTransaction().commit(), but get a runtime error:
Caused by: javax.faces.el.EvaluationException: java.lang.IllegalStateException: A JTA EntityManager cannot use getTransaction()
Is it possible to commit the transaction without returning from an action method?
Thanks!
Report.java:
@Begin(flushMode=FlushModeType.MANUAL, join=true) public void wire() { // nop - placeholder function here only to allow manual flushing config } ... public void generate () { entityManager.persist(foo); entityManager.persist(bar); ... entityManager.flush(); log.debug("committed"); <-----------
If I set breakpoint after the flush, I cannot see the new data persisted to the database from an external client until I exit all the way back out of the top level action function (report.generate()).
Report.page.xml (the page that invokes the backing bean action):
<?xml version="1.0" encoding="UTF-8"?> <page xmlns="http://jboss.com/products/seam/pages" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jboss.com/products/seam/pages http://jboss.com/products/seam/pages-2.0.xsd"> <!-- wire up manually flushed transaction for reports --> <action execute="#{report.wire}"/> </page>
persistence.xml:
<?xml version="1.0" encoding="UTF-8"?> <!-- Persistence deployment descriptor for dev profile --> <persistence 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" version="1.0"> <persistence-unit name="myproject"> <provider>org.hibernate.ejb.HibernatePersistence</provider> <jta-data-source>java:/myprojectDatasource</jta-data-source> <properties> <property name="hibernate.hbm2ddl.auto" value="update"/> <property name="hibernate.cache.use_query_cache" value="true"/> <property name="hibernate.show_sql" value="false"/> <property name="jboss.entity.manager.factory.jndi.name" value="java:/myprojectEntityManagerFactory"/> </properties> </persistence-unit> </persistence>
components.xml:
<persistence:managed-persistence-context name="entityManager" auto-create="true" persistence-unit-jndi-name="java:/myprojectEntityManagerFactory"
myproject-ds.xml:
<?xml version="1.0" encoding="UTF-8"?> <datasources> <local-tx-datasource> <jndi-name>myprojectDatasource</jndi-name> <connection-url>jdbc:mysql:///myproject</connection-url> <driver-class>com.mysql.jdbc.Driver</driver-class> <user-name>myproject</user-name> <password>myproject</password> </local-tx-datasource> </datasources>