-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Problem: Synchronizing Hibernate3 with JTA on WebLogic 8.1
PostPosted: Thu Mar 24, 2005 11:29 am 
Newbie

Joined: Mon Nov 22, 2004 2:11 pm
Posts: 6
Hi,

I want to synchronize the hibernate session with transactions in a JTA environment of an ejb container (WebLogi 8.1) transparently as described at http://www.hibernate.org/245.html "Synchronizing Hibernate3 with JTA".

The session synchronization works fine unless I place 'hibernated' code inside an ejbCreate-method of a Session-Bean. Whenever I do this, no changes are commited to the database.

Let me show an example: (from Main.java)
Code:
  public static void main(String[] args) throws Exception {
     // First try
    {
      Long id = new Long( 50000);
      SampleSession session = SampleSessionUtil.getHome().create();
      session.createMccAgent( id, "dummy2", null);
      session.remove();

      // This worked fine. I can find a new row with ID=50000 inside the DB
    }
   
    // Alternative try
    {
      Long id = new Long( 50001);
      SampleSession session = SampleSessionUtil.getHome().create( id, "dummy3", null);
      session.remove();

      // This didn't work. No new row has been inserted.
    }
  }


This is the server-side code: (from SampleSessionBean.java)
Code:
/**
* @ejb.bean
*   type="Stateful"
*   view-type="remote"
*   name="SampleSession"
*   jndi-name="hsampel/session/SampleSession"
*
* @ejb.transaction
*   type="Required"
*
*
* @ejb.ejb-ref
*    ejb-name="SampleSession" view-type="remote"
*/
public class SampleSessionBean extends AbstractRemoteSessionBean implements SessionBean {
  /**
   * @ejb.create-method
   */
  public void ejbCreate() throws CreateException {
   
  }
  /**
   * @ejb.create-method
   */
  public void ejbCreate( Long id, String ntName, Long mccId) throws CreateException {
    this.createMccAgent( id, ntName, mccId);
  }
  /**
   * @ejb.interface-method
   */
  public void createMccAgent( Long id, String ntName, Long mccId) {
    Session session = null;
    try {
      session = HibernateUtil.instance().getSession();
      MccAgent agent = new MccAgent( id, ntName, mccId);
      session.save( agent);
    } catch ( HibernateException ex ) {
      throw new EJBException( ex);
    }
  } 
}

As you can see, this code does not contain any call to session.flush() or session.close(), since this should be done by Hibernate3 itself when the current transaction is being commited by the EJB container. Actually this happens, when method createMccAgent is called, but not, when method ejbCreate( Long id, String ntName, Long mccId) is called.

For me it looks like the WebLogic TransactionManager does not expose the current Transaction when called within an ejbCreate method, but I am not sure - perhaps I did misconfigure something.

Is this true? If so, what can I do?

Any help would really be appreciated.
Thanks for your time.

Michael



hibernate.cfg.xml:
Code:
<hibernate-configuration>
  <session-factory>
    <property name="connection.datasource">jdbc/HibernateSampleDS</property>
    <property name="jta.UserTransaction">java:comp/UserTransaction</property>
    <property name="transaction.factory_class">org.hibernate.transaction.JTATransactionFactory</property>
    <property name="transaction.manager_lookup_class">org.hibernate.transaction.WeblogicTransactionManagerLookup</property>
    <property name="hibernate.transaction.flush_before_completion">true</property>
    <property name="hibernate.transaction.auto_close_session">true</property>
    <property name="show_sql">true</property>
    <property name="cache.use_query_cache">false</property>
    <property name="dialect">org.hibernate.dialect.OracleDialect</property>
    <property name="hibernate.query.substitutions">true 1, false 0</property>
    <mapping resource="mapping.hbm.xml"/>
  </session-factory>
</hibernate-configuration>

Hibernate version:
3.0
Mapping documents:
Code:
<hibernate-mapping>
  <class name="de.sanacorp.sample.server.interfaces.MccAgent" table="MCC_AGENT">
    <id column="ID" name="id" type="long">
      <generator class="assigned">
      </generator>
     </id>
     <property column="NT_NAME" name="ntName" type="java.lang.String"></property>
     <property column="MCC_ID" name="mccId" type="java.lang.Long"></property>
   </class>   
</hibernate-mapping>

Name and version of the database:
Oracle 8.1


Top
 Profile  
 
 Post subject: Does anybody use Session Synchronization with WebLogic 8?
PostPosted: Sun Apr 17, 2005 7:23 am 
Newbie

Joined: Mon Nov 22, 2004 2:11 pm
Posts: 6
Hi again!

Since I did not receive any reply to my last post I conclude that nobody else experiences that problem. Right? Is that because nobody uses session synchronization with WebLogic 8 and Hibernate 3? Or is that because it works fine for everybody?

If you successfully use session sync. with WebLogic and Hibernate 3, can you please give me a short note? I would be grateful for any reply.

Thanks for your time.

Michael


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.