-->
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.  [ 3 posts ] 
Author Message
 Post subject: NullPointerException in find after java.sql.SQLException
PostPosted: Fri Oct 10, 2003 10:41 am 
Beginner
Beginner

Joined: Fri Oct 10, 2003 10:30 am
Posts: 35
Location: Stockholm
Hi guys. Can't figure this out.
I try to do an insert. If it fails I want to check that it failed because of a duplicate entry.
In pseudo code:
try{
session.connect();
session.save(object);
session.flush();

}catch(Exception){

query="look for the object with name=object.getName()"
session.find(myquery).


}finally{

session.disconnect();
}

The find throws a nullpointer exception.???

If I close and reopen the connection before the find, it works great.
Note that in the query I am using the "name" var, which I get from "object", but it should not matter since it is just string. right?

Any Ideas?
Thanx,
/robcos

-----------

This is the log:


33399 [tcpConnection-6802-0] WARN util.JDBCExceptionReporter - SQL Error: 1062, SQLState: S1009
33399 [tcpConnection-6802-0] ERROR util.JDBCExceptionReporter - Invalid argument value: Duplicate entry '1-a' for key 2
33411 [tcpConnection-6802-0] ERROR util.JDBCExceptionReporter - Could not insert

java.sql.SQLException: Invalid argument value: Duplicate entry '1-name' for key 2
at com.mysql.jdbc.MysqlIO.sendCommand(Unknown Source)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(Unknown Source)
at com.mysql.jdbc.Connection.execSQL(Unknown Source)
at com.mysql.jdbc.PreparedStatement.executeUpdate(Unknown Source)
at com.mysql.jdbc.PreparedStatement.executeUpdate(Unknown Source)
at net.sf.hibernate.persister.EntityPersister.insert(EntityPersister.java:504)
at net.sf.hibernate.persister.EntityPersister.insert(EntityPersister.java:444)
at net.sf.hibernate.impl.SessionImpl.doSave(SessionImpl.java:717)
at net.sf.hibernate.impl.SessionImpl.save(SessionImpl.java:605)
at net.sf.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:1202)
at net.sf.hibernate.engine.Cascades$3.cascade(Cascades.java:88)
at net.sf.hibernate.engine.Cascades.cascade(Cascades.java:258)
at net.sf.hibernate.engine.Cascades.cascade(Cascades.java:298)
at net.sf.hibernate.engine.Cascades.cascade(Cascades.java:341)
at net.sf.hibernate.impl.SessionImpl.preFlushEntities(SessionImpl.java:2285)
at net.sf.hibernate.impl.SessionImpl.flushEverything(SessionImpl.java:2015)
at net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2004)
at com.nmt.msp.util.SimpleMspSession.flush(SimpleMspSession.java:185)
at com.nmt.msp.service.SimpleCampaignService.addUniqueNewsletter(SimpleCampaignService.java:144)
at com.nmt.msp.service.SimpleCampaignService.addNewsletter(SimpleCampaignService.java:164)
at com.nmt.msp.bean.NewsletterBean.add(NewsletterBean.java:316)
at com.nmt.msp.servlet.MspController.service(MspController.java:540)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:103)
at com.caucho.server.http.FilterChainServlet.doFilter(FilterChainServlet.java:96)
at com.caucho.server.http.Invocation.service(Invocation.java:315)
at com.caucho.server.http.CacheInvocation.service(CacheInvocation.java:135)
at com.caucho.server.http.RunnerRequest.handleRequest(RunnerRequest.java:344)
at com.caucho.server.http.RunnerRequest.handleConnection(RunnerRequest.java:274)
at com.caucho.server.TcpConnection.run(TcpConnection.java:139)
at java.lang.Thread.run(Thread.java:536)

DEBUG::SimpleNewsletterService::findByName: query=select newsletter from newsletter in class com.nmt.msp.resource.SimpleNewsletterResource where newsletter.name='name' and newsletter.system= :my_system
java.lang.NullPointerException
at net.sf.hibernate.impl.SessionImpl.flushEntities(SessionImpl.java:2141)
at net.sf.hibernate.impl.SessionImpl.flushEverything(SessionImpl.java:2017)
at net.sf.hibernate.impl.SessionImpl.autoFlushIfRequired(SessionImpl.java:1560)
at net.sf.hibernate.impl.SessionImpl.getQueries(SessionImpl.java:1372)
at net.sf.hibernate.impl.SessionImpl.iterate(SessionImpl.java:1396)
at net.sf.hibernate.impl.QueryImpl.iterate(QueryImpl.java:64)
at com.nmt.msp.service.SimpleNewsletterService.findByName(SimpleNewsletterService.java:1746)
at com.nmt.msp.service.SimpleCampaignService.addNewsletter(SimpleCampaignService.java:171)
at com.nmt.msp.bean.NewsletterBean.add(NewsletterBean.java:316)
at com.nmt.msp.servlet.MspController.service(MspController.java:540)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:103)
at com.caucho.server.http.FilterChainServlet.doFilter(FilterChainServlet.java:96)
at com.caucho.server.http.Invocation.service(Invocation.java:315)
at com.caucho.server.http.CacheInvocation.service(CacheInvocation.java:135)
at com.caucho.server.http.RunnerRequest.handleRequest(RunnerRequest.java:344)
at com.caucho.server.http.RunnerRequest.handleConnection(RunnerRequest.java:274)
at com.caucho.server.TcpConnection.run(TcpConnection.java:139)
at java.lang.Thread.run(Thread.java:536)


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 10, 2003 10:42 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
A Session is doomed after an Exception, you can't reuse it.

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject: thanx
PostPosted: Fri Oct 10, 2003 10:47 am 
Beginner
Beginner

Joined: Fri Oct 10, 2003 10:30 am
Posts: 35
Location: Stockholm
Ok, I did not know.
This explains it, thanx
/robcos


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