-->
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: Hibernate3.1 Upgrade: Error creating Transaction
PostPosted: Wed Dec 21, 2005 8:43 pm 
Beginner
Beginner

Joined: Tue Nov 15, 2005 6:56 pm
Posts: 39
Using Hibernate3.1, Hibernate-tools3.1-beta2, Oracle 10g.

I'm getting an error when trying to create a transaction. Basically, I think the problem is in the changes in SessionImpl and JDBCContext java classes between Hibernate 3.0 to 3.1. It used to work in the older version. We are using our own custom TransactionFactory. I've shown some of the differences in the code below. Anybody have any ideas on how to solve this problem? Thanks.

Here is the error (lines marked with ">>>>" are my own debug):

Code:
     [java] >>>> entering beginTransaction()
     [java] >>>> entering getTransaction()
     [java] >>>>> hibernateTransaction is null
     [java] java.lang.NullPointerException
     [java] at org.hibernate.impl.SessionImpl.beginTransaction(SessionImpl.java:1263)
     [java] at mycompany.myclass.doReport(Myclass.java:327)
     [java] at mycompany.myclass.fillDC(Myclass.java:232)
     [java] at mycompany.myclass.doMain(Myclass.java:145)
     [java] at mycompany.myclass.loadPss(Myclass.java:129)
     [java] at mycompany.myclass.main(Myclass.java:118)


I've looked at the Hibernate source and noticed that the Hibernate SessionImpl class method beginTransaction has changed.

SessionImpl.beginTransaction() used to look like:

Code:
    public Transaction beginTransaction()
        throws HibernateException
    {
        if(!isRootSession)
            log.warn("Transaction started on non-root session");
        Transaction tx = jdbcContext.beginTransaction();
        interceptor.afterTransactionBegin(tx);
        return tx;
    }


SessionImpl.beginTransaction() now looks like in 3.1:

Code:
   public Transaction getTransaction() throws HibernateException {
      return jdbcContext.getTransaction();
   }
   
   public Transaction beginTransaction() throws HibernateException {
      if ( !isRootSession ) {
         log.warn("Transaction started on non-root session");
      }
      Transaction result = getTransaction();
      result.begin();
      return result;
   }


I get a null pointer because my TransactionFactory's createTransaction() method returns null (which used to work before, since this method wasn't really called) when JdbcContext.getTransaction is called (in 3.1):

JdbcContext.getTransaction() looks like:

Code:
public Transaction getTransaction() throws HibernateException {
      
      if (hibernateTransaction==null) {
         hibernateTransaction = owner.getFactory().getSettings()
               .getTransactionFactory()
               .createTransaction( this, owner );
      }
      
      return hibernateTransaction;
   }


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 22, 2005 12:04 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
Sure, return an actual Transaction from your createTransaction() impl...


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.