Hi,
I am working on a project converting EJB CMPs + JDBC code to Hibernate +JDBC codes. And wondering how to create a sub-transaction with Hibernate in CMT env. In EJB CMP this can be achieved by declare the transaction=requiresNew. Is there anything equivallent to this ?
I have read the Hibernate in Action and the documentation, and did not have find any related explainations. I need this as the code is still a mixture of both JDBC SQL code and Hibnerate Code, unless Hibernate code is commited in an new sub-transaction, the JDBC SQL Code can not see the new record/or changes, which will cause the SQL exception in the JDBC Update.
I have tried calling session.flush() and it does not work for me. I have changed the flushmode to COMMIT at the runtime before the Hibernate.save() is called, it still does not work. The following is what I have done:
Code:
session.setFushMode(FlushMode.COMMIT);
session.save(entity);
session.flush();
The entity here uses all the default mapping, basically a class-name, a table name and properties.
I can work around this by create EJB Stateless session bean and mark the transaction as RequiresNew and use hibernate inside this session bean. I would prefer using Hibernate to do this without Stateless session bean.
Anyone has an inside on this ? I did not find any related posting on the forum.
The hibernate cfg mapping file is like this:
Code:
<!-- a SessionFactory instance listed as /jndi/name -->
<session-factory name="hibernate.session_factory">
<!-- properties -->
<property name="connection.datasource">ZG-DATA-SOURCE</property>
<property name="show_sql">true</property>
<property name="use_outer_join">false</property>
<property
name="transaction.manager_lookup_class">org.hibernate.transaction.WeblogicTransactionManagerLookup</property>
<property
name="hibernate.transaction.factory_class">org.hibernate.transaction.JTATransactionFactory</property>
<!-- mapping files -->
<mapping
resource="com/clearstorysystems/ems/persist/ActionBean.hbm.xml"/>
</session-factory>
Noticed that i did not specify the Dialect. As Data source already provides such information.
And the session factory is obtained via JNDI lookat on Session Factory name.
My Env.
OS: LINUX RED HAT Fedora Core 1
App Server: Weblogic 8.1 SP3
Hibernate 3.0.5
Ant 1.6.1
XDoclet 1.2.3
I use XDoclet to generate Hibernate Mapping file
Thanks a lot
Chester Chen