Hi Garth,
have you deployed successfully EJB JPA with Hibernate 3.2.1 applications in WebSphere 6.1 yet ?!!
I'am relatively new to hibernate and WebSphere but have to migrate a time critical project with EM/JPA-hibernate from JBoss to WebSphere 6.1 / CMT.
I have problems to find out the right configuration properties for persistence.xml and so on. Could you give me some short configuration / programming hints to run under above mentioned constellation ??
Especially handling of transaction boundaries and flushing seem to be problematic.
At the bottom you see my persistence.xml and an adapted HibernateUtil class to get the EntityManager.
Thanks a lot,
Tom
Code:
<persistence-unit name="rcl-test" transaction-type="JTA">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<jta-data-source>jdbc/MyDataSource</jta-data-source>
<properties>
<property name="hibernate.archive.autodetection" value="class, hbm"/>
<property name="hibernate.dialect" value="org.hibernate.dialect.OracleDialect" />
<property name="hibernate.show_sql" value="true"/>
<!--property name="hibernate.transaction.factory_class" value="org.hibernate.transaction.CMTTransactionFactory"/-->
<property name="hibernate.session_factory_name" value="MyProject/SessionFactory"/>
<property name="hibernate.transaction.manager_lookup_class" value="org.hibernate.transaction.WebSphereExtendedJTATransactionLookup"/>
<property name="hibernate.jdni.class" value="com.ibm.websphere.naming.WsnInitialContextFactory"/>
<property name="hibernate.jdni.url" value="iiop://localhost:2809/"/>
</properties>
</persistence-unit>
Code:
public class JpaUtil {
private static Log log = LogFactory.getLog(JpaUtil.class);
private static Map<String, EntityManagerFactory> factories = new HashMap<String, EntityManagerFactory>();
/**
* Returns the Entity manager to use.
*
* @return Configuration
*/
public static EntityManager getEntityManager(String persistenceUnit) {
return getEntityManager(persistenceUnit, new HashMap());
}
public static EntityManager getEntityManager(String persistenceUnit, Map overwrite) {
log.info("get entity manager for unit: " + persistenceUnit);
EntityManagerFactory emf = factories.get(persistenceUnit);
if (emf == null) {
log.info(" create NEW manager");
emf = Persistence.createEntityManagerFactory(persistenceUnit, overwrite);
factories.put(persistenceUnit, emf);
}
else {
log.info(" found CACHED manager");
}
EntityManager manager = emf.createEntityManager();
manager.setFlushMode(FlushModeType.AUTO);
return manager;
}