Caine Lai [
http://community.jboss.org/people/unsavory] replied to the discussion
"JBPM 4.3 or 4.4 and LocalContainerEntityManagerFactoryBean"
To view the discussion, visit:
http://community.jboss.org/message/556989#556989
--------------------------------------------------------------
Hi HuiSheng,
Thanks again for your help!
if you wish to get the hibernate session factory from the EntityManagerFactory using Java
code, you would do:
public static SessionFactory getSessionFactory(EntityManagerFactory emf) {
if (emf == null) {
return null;
}
HibernateEntityManagerFactory hemf = (HibernateEntityManagerFactory) emf;
return hemf.getSessionFactory();
}
However, in Spring it is easy to retrieve a sessionFactory from the underlying
entitymanagerfactory like so:
<!-- JPA EntityManagerFactory -->
<bean id="entityManagerFactory">
<property name="dataSource" ref="dataSource" />
<property name="jpaVendorAdapter">
<bean>
<property name="showSql" value="${jpa.showSql}" />
<property name="database" value="${jpa.database}" />
</bean>
</property>
<property name="jpaDialect">
<bean />
</property>
<property name="jpaPropertyMap">
<map>
<!-- Database Configuration -->
<entry key="hibernate.dialect"
value="org.hibernate.dialect.MySQLInnoDBDialect" />
<entry key="hibernate.hbm2ddl.auto"
value="${hibernate.hbm2ddl.auto}" />
<entry key="hibernate.format_sql" value="false" />
<entry key="hibernate.use_sql_comments" value="true" />
<entry key="hibernate.default_batch_fetch_size" value="50" />
<entry key="hibernate.order_updates" value="true" />
<!-- Cache Configuration -->
<!-- <entry key="hibernate.cache.provider_class"
value="net.sf.ehcache.hibernate.SingletonEhCacheProvider" /> -->
<!-- <entry key="net.sf.ehcache.configurationResourceName"
value="ehcache.xml" /> -->
<entry key="hibernate.cache.use_second_level_cache" value="false"
/>
<entry key="hibernate.cache.use_query_cache" value="false" />
<!-- Transaction Management -->
<!-- <entry key="hibernate.current_session_context_class"
value="org.hibernate.context.ThreadLocalSessionContext" /> -->
<entry key="hibernate.current_session_context_class"
value="org.springframework.orm.hibernate3.SpringSessionContext" />
<!-- Hibernate Search -->
<!-- <entry key="hibernate.search.default.directory_provider"
value="false" />
<entry key="hibernate.search.default.indexBase"
value="C:/Temp/hibernate_test_indexes" />
<entry key="hibernate.search.default.batch.merge_factor" value="10"
/>
<entry key="hibernate.search.default.batch.max_buffered_docs"
value="10" />
<entry key="hibernate.search.default.optimizer.operation_limit"
value="500" />
<entry key="hibernate.search.default.optimizer.transaction_limit.max"
value="100" /> -->
</map>
</property>
<!-- Custom implementation to enrich the PersistenceUnitInfo read from the
persistence.xml
JPA configuration file with the JTA datasource. specifying the JTA datasource
directly in
the Spring configuration file has the advantage that we can use a direct reference
to the
datasource instead of using a JNDI name as requied by the jta-data-source setting
in the
persistence.xml file -->
<property name="persistenceUnitPostProcessors">
<bean>
<property name="jtaDataSource" ref="dataSource" />
</bean>
</property>
<property name="loadTimeWeaver">
<bean />
</property>
</bean>
<bean id="sessionFactory" factory-bean="entityManagerFactory"
factory-method="getSessionFactory" />
The sesssion factory returned by this method will be of type HibernateSessionFactory.
Does this help?
--------------------------------------------------------------
Reply to this message by going to Community
[
http://community.jboss.org/message/556989#556989]
Start a new discussion in jBPM at Community
[
http://community.jboss.org/choose-container!input.jspa?contentType=1&...]