-->
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.  [ 1 post ] 
Author Message
 Post subject: EJB2.1 , JPA/Hibernate and CMT on WAS6.1.0.17
PostPosted: Fri Oct 03, 2008 1:37 am 
Newbie

Joined: Tue Mar 06, 2007 10:45 pm
Posts: 2
Hi,

I am trying to use JPA/Hibernate with EJB2.1 and use the CMTs. I wrote a simple method in my Stateless session bean (2.1) to insert an entity say 'Project' in the database.

Code:
   
    public Project insertArifact(Project project) {
            EntityManager em = JPAUtils.getEntityManagerFactory().createEntityManager();
            em.persist(project);
            if(project.getName().equalsIgnoreCase("shivreet")){
             throw new NullPointerException();
             }
       
        return project;

    }


The project that I am trying to insert has the name and thus the EJB would through a RuntimeException rolling back the transaction. But this does not happen. The entity does get inserted. While if i change the method to


Code:
    public Project insertArifact(Project project) {
            EntityManager em = JPAUtils.getEntityManagerFactory().createEntityManager();
            [color=red]em.joinTransaction();[/color]
            em.persist(project);
            if(project.getName().equalsIgnoreCase("shivreet")){
             throw new NullPointerException();
             }
       
        return project;

    }



i.e explicitly join a transaction,it works fine . The JPAUtils is a singleton that returns an EntityManagerFactory based on the following persistence.xml

Code:
   <persistence-unit name="pps-jpa" transaction-type="JTA">
      <provider>org.hibernate.ejb.HibernatePersistence</provider>
      <properties>
         <property name="hibernate.dialect" value="org.hibernate.dialect.Oracle10gDialect" />
         <property name="hibernate.connection.datasource" value="jdbc/XYZ" />
         <property name="hibernate.connection.username" value="user" />
         <property name="hibernate.connection.password" value="password" />
         <property name="hibernate.show_sql" value="true" />
         <property name="hibernate.hibernate.session_factory_name" value="MySessionFactory" />
         <property name="hibernate.max_fetch_depth" value="3" />

         <property name="hibernate.transaction.manager_lookup_class" value="org.hibernate.transaction.WebSphereExtendedJTATransactionLookup" />
         <property name="jta.UserTransaction" value="java:comp/UserTransaction" />
      </properties>
   </persistence-unit>


Any help would be appreciated.

If its any help, I noticed while debugging that when the following call heirarchy is invoked, there is a comment in the JoinableCMTTransactionFactory


checkTransactionSyncStatus(SessionImpl) --> registerSynchronizationIfPossible(JDBCContext)-->
isTransactionInProgress(JDBCContext)-->
isTransactionInProgress(JoinableCMTTransactionFactory)

Code:
public boolean isTransactionInProgress(
         JDBCContext jdbcContext, Context transactionContext, Transaction transaction
   ) {
      if ( transaction == null ) return false; [size=18]//should not happen though[/size]
      JoinableCMTTransaction joinableCMTTransaction = ( (JoinableCMTTransaction) transaction );
      joinableCMTTransaction.tryJoiningTransaction();
      return joinableCMTTransaction.isTransactionInProgress( jdbcContext, transactionContext );
   }
}


And the transaction seems to be null the first time even though I am in the EJB and it returns a false. This is the call heirarchy

[/img]

_________________
Shivreet Sekhon


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

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.