-->
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.  [ 17 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: NullPointerException when saving object
PostPosted: Wed Apr 27, 2005 12:30 pm 
Newbie

Joined: Wed Apr 27, 2005 12:16 pm
Posts: 6
Hi!
i have the following problem:
I try to create (session.save(myObj) ) new object with breaking unique constraint on one of the columns - i get exception unique constraint violation .. that`s ok .. but from this time, whenever i try to create this type of object, i get NullPointerException. No unique constraint is violated, don`t know about any fault on my side. Can anybody please help me?
thanks a lot,
Tomas

[b]Hibernate version:3[/b]

[b]Mapping documents:[/b]

[b]Code between sessionFactory.openSession() and session.close():[/b]

[b]Full stack trace of any exception that occurs:java.lang.NullPointerException at oracle.jdbc.driver.OraclePreparedStatement.setupBindBuffers(OraclePreparedStatement.java:2609) at oracle.jdbc.driver.OraclePreparedStatement.executeBatch(OraclePreparedStatement.java:10240) at com.mchange.v2.sql.filter.FilterPreparedStatement.executeBatch(FilterPreparedStatement.java:260) at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:57) at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:172) at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:226) at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:136) at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:274) at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27) at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:675) at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:293) at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:86) at com.unient.provisioning.pi.hibernate.dao.ProductDao.save(ProductDao.java:55) at com.unient.provisioning.pi.action.product.ProductCreateSubmitAction.execute(ProductCreateSubmitAction.java:54) at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:421) at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:226) at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1164) at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:415) at javax.servlet.http.HttpServlet.service(HttpServlet.java:709) at javax.servlet.http.HttpServlet.service(HttpServlet.java:802) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:237) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157) at com.unient.support.HibernateViewFilter.doFilter(HibernateViewFilter.java:53) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:186) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157) at org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:362) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:186) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:214) at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520) at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:198) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:152) at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:137) at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:118) at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:102) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520) at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:929) at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:160) at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:799) at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:705) at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:577) at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:683) at java.lang.Thread.run(Thread.java:534)[/b]

[b]Name and version of the database you are using:Oracle 10g[/b]

[b]The generated SQL (show_sql=true):[/b]

[b]Debug level Hibernate log excerpt:[/b]


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 27, 2005 2:32 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
So after the unique constraint violation exception you throw away that session and start using a new one, right?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 28, 2005 2:26 am 
Newbie

Joined: Wed Apr 27, 2005 12:16 pm
Posts: 6
Of course i do ... i create new hibernate session and i still get NullPointerException when i try to create this type of object. I can still create all other types, but when i violate unique constraint on whatever type of object, i get this problem again.
Even if i close browser window and try to connect from new web browser, i still can`t create new objects. Only restart of the server helps

T.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 28, 2005 9:10 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
Guess I need to pull teeth today...

Show us your usage code


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 28, 2005 9:24 am 
Newbie

Joined: Wed Apr 27, 2005 12:16 pm
Posts: 6
***This is part of my struts action class

Product p = new Product();
p.setName((String)f.get("name"));
p.setDescription((String)f.get("description"));
ProductDao.save(p);


***save method in my ProductDao class:

public static void save(Product p) throws Exception {
Transaction tx = HibernateViewFilter.openSession().beginTransaction();
if (p.getID() == 0) {
LOG.debug("creating product .. "+p.getName()+" : "+p.getID());
HibernateViewFilter.openSession().save(p);
tx.commit();
} else {
HibernateViewFilter.openSession().update(p);
tx.commit();
}
LOG.debug("product SAVED: " + p.getName()+" : "+p.getID());
}


***HibernateViewFilter's opensession method: (sf is sessionFactory):

public static Session openSession() throws HibernateException {
Session s = (Session) hibernateHolder.get();
if (s == null) {
s = sf.openSession();
hibernateHolder.set(s);
}
return s;
}

***and this is ProductDAO.hbm.xml file
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping>

<class name="com.unient.provisioning.pi.hibernate.Product" table="PRODUCT">

<id name="ID">
<column name="ID" unique="true"/>
<generator class="sequence">
<param name="sequence">product_id_seq</param>
</generator>
</id>

<property name="name" unique="true" not-null="true"/>
<property name="description"/>
<property name="xmlSchema"/>
</class>

</hibernate-mapping>


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 28, 2005 5:38 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
OK, so I see one attempt to save/update something. You said there are two attempts.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 29, 2005 2:24 am 
Newbie

Joined: Wed Apr 27, 2005 12:16 pm
Posts: 6
yes, i have two attempts - but made by user interaction from web browser...
user can create instance of Product type by calling "save(product)" method as many times as he wishes ... problem is, when user enters duplicate name - Then of course arises unique constraint violation exception - that`s ok .. but from this time, whenever is called method "save(product)", i get described NullPointerException.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 29, 2005 8:36 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
So try the following outside your webapp, like maybe in a simple main or JUnit test:

Code:

Product p = new Product();
p.setName( "some existing name" );
p.setDescription( "should fail" );

Session session = getFactory().openSession();
Transaction tx = session.beginTransaction();

// assume this block gives us the unique constraint violation
try {
    // why not just use session.saveOrUpdate() here?!?
    if (p.getID() == 0) {
        session.save( p );
    }
    else {
        session.update( p );
    }
    tx.commit();
}
catch( Throwable t ) {
    tx.rollback();
}
finally {
    if ( session != null ) {
        try {
            session.close();
        }
        catch( Throwable ignore ) {
        }
    }
}

// so now attempt the second persist...
Product p2 = new Product();
p2.setName( "some non-existing name" );
p2.setDescription( "should pass" );

session = getFactory().openSession();
tx = session.beginTransaction();
try {
    session.saveOrUpdate( p2 );
    tx.commit();
}
catch( Throwable t ) {
    tx.rollback();
}
finally {
    if ( session != null ) {
        try {
            session.close();
        }
        catch( Throwable ignore ) {
        }
    }
}



If this works (which I'm fairly certain it will), then you most likely have a problem with your session handling.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 29, 2005 10:04 am 
Newbie

Joined: Wed Apr 27, 2005 12:16 pm
Posts: 6
[b]Hi again!
i tried exactly your code - as main class, i just added t.printStackTrace to see exceptions - and i have the same result as i had in my web application!

here is my code:[/b]

/*
* NewMain.java
*
* Created on 29. duben 2005, 15:41
*/

[code]package com.unient.support;
import com.unient.provisioning.pi.hibernate.*;
import org.hibernate.*;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
/**
*
* @author vajrauch
*/
public class NewMain {

/** Creates a new instance of NewMain */
public NewMain() {
}

/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Product p = new Product();
p.setName( "Viphone" );
p.setDescription( "should fail" );
SessionFactory sf = new Configuration().configure("/hibernate.cfg.xml").buildSessionFactory();

Session session = sf.openSession();
Transaction tx = session.beginTransaction();

// assume this block gives us the unique constraint violation
try {
// why not just use session.saveOrUpdate() here?!?
if (p.getID() == 0) {
session.save( p );
} else {
session.update( p );
}
tx.commit();
} catch( Throwable t ) {
tx.rollback();
t.printStackTrace();
} finally {
if ( session != null ) {
try {
session.close();
} catch( Throwable ignore ) {
ignore.printStackTrace();
}
}
}

// so now attempt the second persist...
Product p2 = new Product();
p2.setName( "bghhghgfsddf" );
p2.setDescription( "should pass" );

session = sf.openSession();
tx = session.beginTransaction();
try {
session.saveOrUpdate( p2 );
tx.commit();
} catch( Throwable t ) {
tx.rollback();
t.printStackTrace();
} finally {
if ( session != null ) {
try {
session.close();
} catch( Throwable ignore ) {
ignore.printStackTrace();
}
}
}
}

}[/code]

[b]
and this is the exception i`ve got:[/b]
org.hibernate.exception.ConstraintViolationException: Could not execute JDBC batch update
at org.hibernate.exception.ErrorCodeConverter.convert(ErrorCodeConverter.java:74)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:179)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:226)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:136)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:274)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:675)
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:293)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:86)
at com.unient.support.NewMain.main(NewMain.java:42)
Caused by: java.sql.BatchUpdateException: ORA-00001: unique constraint (PI.UQ_PRODUCT_NAME) violated

at oracle.jdbc.driver.DatabaseError.throwBatchUpdateException(DatabaseError.java:522)
at oracle.jdbc.driver.OraclePreparedStatement.executeBatch(OraclePreparedStatement.java:10306)
at com.mchange.v2.sql.filter.FilterPreparedStatement.executeBatch(FilterPreparedStatement.java:260)
at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:57)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:172)
... 8 more
java.lang.NullPointerException
at oracle.jdbc.driver.OraclePreparedStatement.setupBindBuffers(OraclePreparedStatement.java:2609)
at oracle.jdbc.driver.OraclePreparedStatement.executeBatch(OraclePreparedStatement.java:10240)
at com.mchange.v2.sql.filter.FilterPreparedStatement.executeBatch(FilterPreparedStatement.java:260)
at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:57)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:172)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:226)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:136)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:274)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:675)
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:293)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:86)
at com.unient.support.NewMain.main(NewMain.java:65)

[b]The exception rises on row no. 65 - this is tx.commit() after session.saveOrUpdate( p2 );[/b]

[/b]


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 05, 2005 3:02 am 
Newbie

Joined: Wed Apr 27, 2005 12:16 pm
Posts: 6
Hi again,
I found out this problem is not only in case of Unique constraint violation, but in case of any Ora Exception .. now i try to make insert of one type and got ORA exception: Value too large for column - and from this time i have the same problem - Null pointer exception on save of this type .. only restart of the server helps ...
do you have any new suggestions?


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 05, 2005 10:43 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
I am assuming this is yet another Oracle driver bug. But feel free to create a JIRA case and attach a small runnable test case reproducing this problem if you think otherwise.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 08, 2005 9:55 am 
Newbie

Joined: Tue Jun 07, 2005 9:37 am
Posts: 2
Location: Poznan, Poland
I had similiar problem but with MSSQL server with replication on. If anyone knows the source of this exception, please reply

_________________
<b> Ranisz </>


Top
 Profile  
 
 Post subject:
PostPosted: Sat Sep 17, 2005 3:16 am 
Newbie

Joined: Sat Sep 17, 2005 3:07 am
Posts: 1
Location: Vietnam
I had the same bug with iBatis. After that I didn't use the batch update, use loop instead and now It's OK.
Try to do with Hibernate.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 06, 2005 6:19 pm 
Newbie

Joined: Tue Mar 15, 2005 1:38 pm
Posts: 11
steve wrote:
I am assuming this is yet another Oracle driver bug. But feel free to create a JIRA case and attach a small runnable test case reproducing this problem if you think otherwise.


I just ran into this problem with a production application of mine. Caused a crash. Very annoying. Steve is correct in that this is definitely an Oracle JDBC driver bug. I was able to write a simple test case using plain old JDBC to reproduce the problem. Further testing revealed that the latest Oracle JDBC driver (10.2.0.1.0) resolves this issue completely. In fact, this issue is mentioned as one of the bugs fixed in the release.

From the README:

BUG-4365273
NullPointerException when calling executeBatch after previous call
on same statement resulted in an error. This problem occurs
occasionally when using statement caching and Fast Connection
Failover. A workaround is to call clearBatch in a catch block
wrapped around the call to executeBatch.

--

So for those of you experiencing this problem upgrading to the 10.2.0.1.0 Oracle JDBC driver will fix the problem.

Corey


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 06, 2005 6:25 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Yeroc wrote:
BUG-4365273

Holy cow! Did they make a party for the 4,000,000th bug? lol

_________________
Emmanuel


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

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.