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.  [ 4 posts ] 
Author Message
 Post subject: NPE in AbstractBatcher.getPreparedStatement
PostPosted: Wed Apr 26, 2006 4:27 am 
Newbie

Joined: Tue Oct 25, 2005 6:04 am
Posts: 10
I use hibernate in JBoss with managed sessions and transactions. Up until recently the session factory was configured to use a local-tx datasource and everything worked fine. However, I needed to add more datasources to use in XA transactions, so I converted the old datasource to a xa-datasource. The xa stuff works fine and most other things too, but this particular thing stopped working. When I put the old local-tx datasource back in place, this works again.

Any ideas why this doesn't work with a xa-datasource?

Hibernate version:
3.0 (that comes with JBoss 4.0.3SP1)

Mapping documents:

Code:
<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE hibernate-mapping PUBLIC
    "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
    "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping

>

    <class
            name="hr.chipoteka.erp.data.PosjetKupcu"
            lazy="false"
    >

    <id
        name="posjetID"
            column="posjetID"
            unsaved-value="null"
    >

    <!-- The generator-class attribute of @hibernate.id is deprecated, use the @hibernate.generator tag instead -->
    <generator class="native">

    </generator>

    </id>

        <version
            name="ts"
            column="ts"
            type="timestamp"
        />

        <many-to-one
            name="djel"
                    column="djelID"
                not-null="true"
                outer-join="true"
        >

        </many-to-one>

        <property
            name="datum"
                not-null="true"
        >

            <column
                name="datum"
                sql-type="timestamp(0)"
            />

        </property>

        <many-to-one
            name="kupac"
                    column="kupacID"
                not-null="true"
                outer-join="true"
        >

        </many-to-one>

        <many-to-one
            name="vozilo"
                    column="voziloID"
                not-null="true"
                outer-join="true"
        >

        </many-to-one>

        <property
            name="pocetniKm"
                not-null="true"
        >

        </property>

        <property
            name="udaljenost"
                not-null="true"
        >

        </property>

        <property
            name="opis"
                length="1024"
        >

        </property>

    </class>   

</hibernate-mapping>



Code between sessionFactory.openSession() and session.close():
Code:
PosjetKupcu p;
// intitialize p...

session.saveOrUpdate(p)


Full stack trace of any exception that occurs:
Code:
2006-04-25 16:31:26,415 ERROR [org.jboss.ejb.plugins.LogInterceptor] TransactionRolledbackException in method: public abstract hr.chipoteka.erp.data.DataObject hr.chipoteka.erp.server.interfaces.PosjetKupcuBn.spremi(hr.chipoteka.erp.data.DataObject)
throws hr.chipoteka.erp.SessionException,java.rmi.RemoteException, causedBy:
org.jboss.tm.JBossRollbackException: Unable to commit, tx=TransactionImpl:XidImpl[FormatId=257, GlobalId=kreso/201, BranchQual=, localId=201] status=STATUS_NO_TRANSACTION; - nested throwable: (java.lang.NullPointerException)
        at org.jboss.tm.TransactionImpl.commit(TransactionImpl.java:354)
        at org.jboss.ejb.plugins.TxInterceptorCMT.endTransaction(TxInterceptorCMT.java:486)
        at org.jboss.ejb.plugins.TxInterceptorCMT.runWithTransactions(TxInterceptorCMT.java:346)
        at org.jboss.ejb.plugins.TxInterceptorCMT.invoke(TxInterceptorCMT.java:166)
        at org.jboss.ejb.plugins.SecurityInterceptor.invoke(SecurityInterceptor.java:153)
        at org.jboss.ejb.plugins.LogInterceptor.invoke(LogInterceptor.java:192)
        at org.jboss.ejb.plugins.ProxyFactoryFinderInterceptor.invoke(ProxyFactoryFinderInterceptor.java:122)
        at org.jboss.ejb.SessionContainer.internalInvoke(SessionContainer.java:624)
        at org.jboss.ejb.Container.invoke(Container.java:873)
        at sun.reflect.GeneratedMethodAccessor91.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:585)
        at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:141)
        at org.jboss.mx.server.Invocation.dispatch(Invocation.java:80)
        at org.jboss.mx.server.Invocation.invoke(Invocation.java:72)
        at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:245)
        at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:644)
        at org.jboss.invocation.jrmp.server.JRMPInvoker$MBeanServerAction.invoke(JRMPInvoker.java:805)
        at org.jboss.invocation.jrmp.server.JRMPInvoker.invoke(JRMPInvoker.java:406)
        at sun.reflect.GeneratedMethodAccessor90.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:585)
        at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:294)
        at sun.rmi.transport.Transport$1.run(Transport.java:153)
        at java.security.AccessController.doPrivileged(Native Method)
        at sun.rmi.transport.Transport.serviceCall(Transport.java:149)
        at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:460)
        at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:701)
        at java.lang.Thread.run(Thread.java:595)
Caused by: java.lang.NullPointerException
        at org.hibernate.jdbc.AbstractBatcher.getPreparedStatement(AbstractBatcher.java:439)
        at org.hibernate.jdbc.AbstractBatcher.prepareStatement(AbstractBatcher.java:93)
        at org.hibernate.jdbc.AbstractBatcher.prepareStatement(AbstractBatcher.java:86)
        at org.hibernate.persister.entity.AbstractEntityPersister.update(AbstractEntityPersister.java:2165)
        at org.hibernate.persister.entity.AbstractEntityPersister.updateOrInsert(AbstractEntityPersister.java:2117)
        at org.hibernate.persister.entity.AbstractEntityPersister.update(AbstractEntityPersister.java:2373)
        at org.hibernate.action.EntityUpdateAction.execute(EntityUpdateAction.java:84)
        at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:243)
        at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:227)
        at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:141)
        at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:296)
        at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
        at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:905)
        at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:345)
        at org.hibernate.transaction.CacheSynchronization.beforeCompletion(CacheSynchronization.java:59)
        at org.jboss.tm.TransactionImpl.doBeforeCompletion(TransactionImpl.java:1473)
        at org.jboss.tm.TransactionImpl.beforePrepare(TransactionImpl.java:1092)
        at org.jboss.tm.TransactionImpl.commit(TransactionImpl.java:306)
        ... 28 more



Name and version of the database you are using:
Postgres 8.1 on Debian

The generated SQL (show_sql=true):
Code:
update PosjetKupcu set ts=?, djelID=?, datum=?, kupacID=?, voziloID=?, pocetniKm=?, udaljenost=?, opis=? where posjetID=? and ts=?


Debug level Hibernate log excerpt:
Code:
2006-04-25 16:31:26,414 DEBUG [org.hibernate.jdbc.AbstractBatcher] preparing statement
2006-04-25 16:31:26,414 DEBUG [org.hibernate.jdbc.JDBCContext] before transaction completion
2006-04-25 16:31:26,414 DEBUG [org.hibernate.impl.SessionImpl] before transaction completion
2006-04-25 16:31:26,415 DEBUG [org.hibernate.transaction.CacheSynchronization] transaction after completion callback, status: 4
2006-04-25 16:31:26,415 DEBUG [org.hibernate.jdbc.JDBCContext] after transaction completion
2006-04-25 16:31:26,415 DEBUG [org.hibernate.impl.SessionImpl] after transaction completion
--- here comes the above exception ---


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 27, 2006 1:02 am 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
The NPE is being caused by connectionManager.getConnection() returning null. Which connection manager are you using? It's configured using hibernate.connection.provider_class.

If you can find and put a breakpoint in the getConnection() method of the provider you're using, then find out what's going wrong in that method. Alternatively, you could experiment with a few different managers that come with hibernate (in the org.hibernate.connection package) to find one that works and meets your requirements.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 27, 2006 2:55 am 
Newbie

Joined: Tue Oct 25, 2005 6:04 am
Posts: 10
tenwit wrote:
The NPE is being caused by connectionManager.getConnection() returning null. Which connection manager are you using? It's configured using hibernate.connection.provider_class.

I don't know. Whichever one JBoss uses. Here are my datasources:

The local-tx (which works):
Code:
<datasources>
   <local-tx-datasource>
      <jndi-name>jdbc/ChipDS</jndi-name>
      <connection-url>jdbc:postgresql://localhost/Chipoteka</connection-url>
      <driver-class>org.postgresql.Driver</driver-class>
      <user-name>jboss</user-name>
      <password>jboss</password>
      <min-pool-size>5</min-pool-size>
      <max-pool-size>20</max-pool-size>
      <idle-timeout-minutes>5</idle-timeout-minutes>
      <check-valid-connection-sql>select 1</check-valid-connection-sql>
      <set-tx-query-timeout>true</set-tx-query-timeout>
      <metadata>
         <type-mapping>PostgreSQL 8.1</type-mapping>
      </metadata>
   </local-tx-datasource>
</datasources>

Here is the xa-datasource that fails:
Code:
<datasources>
   <xa-datasource>
      <jndi-name>jdbc/ChipDS</jndi-name>
      <track-connection-by-tx>true</track-connection-by-tx>
      <xa-datasource-class>org.postgresql.xa.PGXADataSource</xa-datasource-class>
      <xa-datasource-property name="ServerName">localhost</xa-datasource-property>
      <xa-datasource-property name="DatabaseName">Chipoteka</xa-datasource-property>
      <xa-datasource-property name="User">jboss</xa-datasource-property>
      <xa-datasource-property name="Password">jboss</xa-datasource-property>      
      <track-statements>true</track-statements>
      <track-connection-by-tx>true</track-connection-by-tx>
      <min-pool-size>5</min-pool-size>
      <max-pool-size>20</max-pool-size>
      <idle-timeout-minutes>5</idle-timeout-minutes>
      <set-tx-query-timeout>true</set-tx-query-timeout>
      <metadata>
         <type-mapping>PostgreSQL 8.1</type-mapping>
      </metadata>
   </xa-datasource>
</datasources>


Quote:
If you can find and put a breakpoint in the getConnection() method of the provider you're using, then find out what's going wrong in that method. Alternatively, you could experiment with a few different managers that come with hibernate (in the org.hibernate.connection package) to find one that works and meets your requirements.


This brings up a question that I have been struggling with for some time: which source for hibernate should I read? I use eclipse and have tried attaching source to the hibernate library, but the debugger alwas shows executable lines where source has nothing or wrong code, clearly shoving that I use the wrong sources. I have tried with 3.1RC1, 2 and 3, 3.1, 3.1.1 and 3.1.2. The manifest in hibernate3.jar included with jboss suggests it should be 3.1RC2, but line numbers just don't match. I tried with jboss source code, but it includes only the hibernate library, not the source of if (understandably). I even tried with decompliers with mixed results. Which source should I attach???[/code]


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 27, 2006 3:52 am 
Newbie

Joined: Tue Oct 25, 2005 6:04 am
Posts: 10
I have finally found the source of the problem: In some specific cases, I did some additional checks on the data in another method (way above my call to saveOrUpdate). This method remained unchanged from the time I used manual session management, and it closed the session before exiting. I was certain that it was an issue with xa-datasources, but I overlooked a subtle difference in my tests. Sorry to waste your time.

Anyway, I'm filing a bug report for a clearer error message.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.