No Commit to DB on JSF - EJB - OpenJPA

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

No Commit to DB on JSF - EJB - OpenJPA

faehne
Hi,

i'm doing some db-updates via OpenJPA, that are not written to DB (but TRACE shows the sql-update and the commit).
Only on Server shutdown it will be written to DB.

The call-hierarchie is:
request-scoped jsfbean --> select entitybean --> ejb-call with enitybean as param --> em.merge

Here are my code and config:

----------------------------------------
EJB:
----------------------------------------
@Stateless
public class UserServiceBean implements UserService {

       
        @PersistenceContext(unitName="AmePersistenceUnit")
        EntityManager entityManager;

        ...
       
        @Override
        public User update(User obj) {
                System.out.println("===========================UPDATE START=========================");
                User usr = entityManager.merge(obj);
                entityManager.flush();
                System.out.println("===========================UPDATE END=========================");
                return usr;
        }
        ...
}

----------------------------------------
perstistence.xml:
----------------------------------------

<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.0"
 xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
 http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">
 
 <persistence-unit name="AmePersistenceUnit" transaction-type="JTA">
 <description>Persistence Unit fuer die AmeEnities</description>
 <jta-data-source>DS</jta-data-source>
 

 <class>xxx.User</class>
 <properties>
  <property name="openjpa.Log" value="DefaultLevel=TRACE, Runtime=TRACE, Tool=TRACE, SQL=TRACE"/>
  <property name="openjpa.jdbc.SynchronizeMappings" value="buildSchema" />
 </properties>
 
 </persistence-unit>
</persistence>

----------------------------------------
managed bean (JSF):
----------------------------------------
public class Testing {

        @EJB(name="...")
        private AmeUserService userService;
       
        public void test()
        {
                System.out.println("==================== START Testing ===================");
               
                User user = users.get(0);
                System.out.println(user.getName());
                user.setVersuche(0);
                user.setLoggedIn("J");
                userService.update(user);
               
                System.out.println("==================== STOP  Testing ===================");
        }
}
Reply | Threaded
Open this post in threaded view
|

Re: No Commit to DB on JSF - EJB - OpenJPA

SergeyM
If you use an Oracle DataSource, you need to set config parameter id DataSource:
<config-property-setting name="CommitBeforeAutocommit">true</config-property-setting>