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)
|