Hi,
I use hibernate 3.2.2 instead of openjpa as JPA 1.0 provider for my EJBs. All hibernate dependencies are put into a WAS shared library and EAR with EJB jars refers them. The application starts well and seems no exceptions are printed in any level. Query entity operations work very well. Whereas I find each update/insert operation cannot be done to database, unless I manually add entityManager.flush() method before each end of my SLSBs. I also tested the same code in JBoss and weblogic, which do not have the problem both. Anyone met the same issue?
Here's my persistence.xml sample, websphere version:
Code:
<?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"
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="mes.platform" transaction-type="JTA">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<jta-data-source>jdbc/mes_platform</jta-data-source>
<properties>
<!-- Auto detect annotation model classes -->
<property name="hibernate.archive.autodetection" value="class" />
<property name="hibernate.dialect" value="org.hibernate.dialect.Oracle10gDialect" />
<property name="hibernate.show_sql" value="false"/>
<property name="hibernate.format_sql" value="true"/>
<property name="hibernate.cache.use_query_cache" value="true"/>
<property name="hibernate.cache.use_second_level_cache" value="true"/>
<property name="hibernate.cache.region_prefix" value="mes"/>
<property name="hibernate.cache.provider_class" value="org.hibernate.cache.EhCacheProvider"/>
<property name="hibernate.transaction.manager_lookup_class" value="org.hibernate.transaction.WebSphereExtendedJTATransactionLookup"/>
<property name="hibernate.transaction.factory_class" value="org.hibernate.transaction.CMTTransactionFactory"/>
<property name="jta.UserTransaction" value="java:comp/UserTransaction"/>
</properties>
</persistence-unit>
</persistence>
And here are my code in SLSB:
Code:
public <T extends Entity> T createEntity(T entity, String sessionId)
{
entity.validate();
String id = entity.getId();
if ((id == null) || (id.trim().isEmpty())) {
entity.setId(UUID.randomUUID().toString());
}
getEntityManager().persist(entity);
///////////////
//here I should flush it, or the entity created cannot be writen to database eventually
if(isWebsphere()){
getEntityManager().flush();
}
//////////////
return entity;
}
Regards,
Jay