Hibernate on Websphere AS, strange problem. Pls Help
Dear All,
I am using Struts with Spring and Hibernate on WAS 6.0
All is fine. The first request comes through and the database is updated.
However the next request onwards I get a Null Pointer Exception. With no stack trace or anything.
The NPE is thrown for random tables(most of the times the 1st table)(the request updates 5 tables).
I have tried to do this exercise with MySql, and it works like a charm.
I am using oracle9 and Hibernate 3. The updatations happen in my class which extends the HibernateDaoSupport using getHibernateTemplate().save(<object>)
and my applicationContext.xml also takes care of eliminating the need for the hibernate config xml.
If I exit the env. and open it again, it will repeat the same exercise. I have been pulling my hair out for more than a couple of days now.
I have all the WAS env variables set (ojdbc14.jar/zip).
Any helpful suggestion, appreciated. :-)
TIA
# 1
and sure.. u bet.. I have searched the globe already for solutions but no luck :-(
# 2
> However the next request onwards I get a Null Pointer
> Exception. With no stack trace or anything.
Sounds like you're handling the exception incorrectly. Post the exception handling logic please. You need to make sure that the logging gets the full exception. If you're just doing a System.out.println(e); or a log.debug(e); or somesuch you'll just get the NPE without any stack trace. Which, as you've noticed, makes debugging rather harder.
> I have tried to do this exercise with MySql, and it
> works like a charm.
You're almost certainly breaking a database constraint (most likely a not-null). MySQL accepts any old rubbish and puts a default value in its place, which is a very good reason not to use MySQL if your data is important.
The real databases are producing an error when you try to carry out the bad insert, then your exception handler is masking the origin of the problem.
> I am using oracle9 and Hibernate 3. The updatations
> happen in my class which extends the
> HibernateDaoSupport using
> getHibernateTemplate().save(<object>)
Good. That pretty much eliminates connection/session leaks.
Fix the logging first, then show us the stack trace and associated code (unless you spot the bug yourself at that point). Show us the mapping file and table DDL for the entity that you're saving as well please.
D.
# 3
Dear Dave,
Thanks much for replying.
>Sounds like you're handling the exception incorrectly. Post the >exception handling logic please. You need to make sure that the >logging gets the full exception. If you're just doing a System.out.println>>(e); or a log.debug(e); or somesuch you'll just get >the NPE without any stack trace. Which, as you've noticed, makes >
>debugging rather harder.
no major logic there.. just a try catch with a e.printStackTrace().
Please guide me as to how can I properly have an exception handling logic in place. I'll put it in there, and post back the exact trace. As of now, this is the trace
[3/21/07 16:25:33:694 IST] 00000043 SystemOutO Hibernate: insert into TEST_APPLICANT_DATA1 (FIRSTNAME, LASTNAME, ADDRESS, ADDRESS1, ZIPCODE, CITY, STATE, SELCREDIT, SSN, RESIDENCE, RESIDENTSINCE, PREVIOUSRESIDENT, QUOTATIONNUMBER) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
[3/21/07 16:25:33:725 IST] 00000043 SystemOutO java.lang.NullPointerException
[3/21/07 16:28:40:814 IST] 00000043 SystemOutO Hibernate: insert into TEST_APPLICANT_DATA1 (FIRSTNAME, LASTNAME, ADDRESS, ADDRESS1, ZIPCODE, CITY, STATE, SELCREDIT, SSN, RESIDENCE, RESIDENTSINCE, PREVIOUSRESIDENT, QUOTATIONNUMBER) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
[3/21/07 16:28:41:158 IST] 00000043 SystemOutO updated the database with Serial value as :
[3/21/07 16:28:41:158 IST] 00000043 SystemOutO 18
[3/21/07 16:28:41:158 IST] 00000043 SessionFactor I org.hibernate.impl.SessionFactoryImpl close closing
[3/21/07 16:28:50:870 IST] 00000058 SystemOutO Hibernate: insert into TEST_APPLICANT_DATA1 (FIRSTNAME, LASTNAME, ADDRESS, ADDRESS1, ZIPCODE, CITY, STATE, SELCREDIT, SSN, RESIDENCE, RESIDENTSINCE, PREVIOUSRESIDENT, QUOTATIONNUMBER) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
[3/21/07 16:28:50:870 IST] 00000058 SystemOutO java.lang.NullPointerException
[3/21/07 16:28:59:705 IST] 00000043 SystemOutO Hibernate: insert into TEST_APPLICANT_DATA1 (FIRSTNAME, LASTNAME, ADDRESS, ADDRESS1, ZIPCODE, CITY, STATE, SELCREDIT, SSN, RESIDENCE, RESIDENTSINCE, PREVIOUSRESIDENT, QUOTATIONNUMBER) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
[3/21/07 16:28:59:752 IST] 00000043 SystemOutO updated the database with serial value as :
[3/21/07 16:28:59:752 IST] 00000043 SystemOutO 20
[3/21/07 16:28:59:752 IST] 00000043 SessionFactor I org.hibernate.impl.SessionFactoryImpl close closing
>You're almost certainly breaking a database constraint (most likely a
you bet. Now I know why i was getting "value too large for column" errors. After looking around everywhere, I really didnt find anything that was too big for the column, I dropped everyconstraint.
Thanks a ton in advance.
# 4
And what's in SystemErr.log ?
# 5
> I dropped everyconstraint.That doesn't sound a great idea...
# 6
My mapping file
<hibernate-mapping>
<class name="com.ellume.resource.ucrealisation.test.Form.ApplicantInfoForm" table="TEST_APPLICANT_DATA1">
<id name="quotationNumber" type="long" column="QUOTATIONNUMBER" >
<generator class="increment">
</generator>
</id>
<property name="firstName">
<column name="FIRSTNAME" />
</property>
<property name="lastName">
<column name="LASTNAME"/>
</property>
<property name="address">
<column name="ADDRESS"/>
</property>
<property name="address1">
<column name="ADDRESS1"/>
</property>
<property name="zipCode">
<column name="ZIPCODE"/>
</property>
<property name="city">
<column name="CITY"/>
</property>
<property name="state">
<column name="STATE"/>
</property>
<property name="selcredit">
<column name="SELCREDIT"/>
</property>
<property name="txtssn">
<column name="SSN"/>
</property>
<property name="selResidence">
<column name="RESIDENCE"/>
</property>
<property name="selResidenceYr">
<column name="RESIDENTSINCE"/>
</property><property name="selPrevresYr">
<column name="PREVIOUSRESIDENT"/>
</property>
</class>
</hibernate-mapping>
The table created in oracle maps to the same.
TIA
# 7
>>That doesn't sound a great idea...
..for the time being.
This is whats there in SystemErr
[3/21/07 16:49:45:622 IST] 000000af SystemErrR
[3/21/07 16:49:45:700 IST] 000000af SystemErrR java.lang.NullPointerException
at oracle.jdbc.dbaccess.DBData.clearItem(DBData.java:431)
at oracle.jdbc.dbaccess.DBDataSetImpl.clearItem(DBDataSetImpl.java:3528)
at oracle.jdbc.driver.OraclePreparedStatement.clearParameters(OraclePreparedStatement.java:3401)
at com.ibm.ws.rsadapter.jdbc.WSJdbcConnection.resetStatement(WSJdbcConnection.java:2240)
at com.ibm.ws.rsadapter.jdbc.WSJdbcConnection.prepareStatement(WSJdbcConnection.java:1891)
at com.ibm.ws.rsadapter.jdbc.WSJdbcConnection.prepareStatement(WSJdbcConnection.java:1843)
at org.hibernate.jdbc.AbstractBatcher.getPreparedStatement(AbstractBatcher.java:497)
at org.hibernate.jdbc.AbstractBatcher.prepareStatement(AbstractBatcher.java:94)
at org.hibernate.jdbc.AbstractBatcher.prepareStatement(AbstractBatcher.java:87)
at org.hibernate.jdbc.AbstractBatcher.prepareBatchStatement(AbstractBatcher.java:218)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2174)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2610)
at org.hibernate.action.EntityInsertAction.execute(EntityInsertAction.java:52)
at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:248)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:232)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:139)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:298)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1000)
at org.springframework.orm.hibernate3.HibernateAccessor.flushIfNecessary(HibernateAccessor.java:210)
at org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:312)
at org.springframework.orm.hibernate3.HibernateTemplate.save(HibernateTemplate.java:536)
at com.ellume.resource.dao.ucrealisation.test.ApplicantInfoDao.insertCustomer(ApplicantInfoDao.java:50)
at com.ellume.presentation.ucrealisation.test.action.updateDao.execute(updateDao.java:36)
at org.springframework.web.struts.DelegatingActionProxy.execute(DelegatingActionProxy.java:105)
at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:484)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:274)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)
at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:525)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:763)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1572)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:762)
at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.forward(WebAppRequestDispatcher.java:334)
at org.apache.struts.action.RequestProcessor.doForward(RequestProcessor.java:1069)
at org.apache.struts.action.RequestProcessor.processForwardConfig(RequestProcessor.java:455)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:279)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)
at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:525)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:763)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1572)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:762)
at com.ibm.ws.webcontainer.webapp.WebApp.handleRequest(WebApp.java:3071)
at com.ibm.ws.webcontainer.webapp.WebGroup.handleRequest(WebGroup.java:236)
at com.ibm.ws.webcontainer.VirtualHost.handleRequest(VirtualHost.java:210)
at com.ibm.ws.webcontainer.WebContainer.handleRequest(WebContainer.java:1958)
at com.ibm.ws.webcontainer.channel.WCChannelLink.ready(WCChannelLink.java:109)
at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleDiscrimination(HttpInboundLink.java:472)
at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleNewInformation(HttpInboundLink.java:411)
at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.ready(HttpInboundLink.java:288)
at com.ibm.ws.tcp.channel.impl.NewConnectionInitialReadCallback.sendToDiscriminaters(NewConnectionInitialReadCallback.java:207)
at com.ibm.ws.tcp.channel.impl.NewConnectionInitialReadCallback.complete(NewConnectionInitialReadCallback.java:109)
at com.ibm.ws.tcp.channel.impl.WorkQueueManager.requestComplete(WorkQueueManager.java(Compiled Code))
at com.ibm.ws.tcp.channel.impl.WorkQueueManager.attemptIO(WorkQueueManager.java(Compiled Code))
at com.ibm.ws.tcp.channel.impl.WorkQueueManager.workerRun(WorkQueueManager.java(Compiled Code))
at com.ibm.ws.tcp.channel.impl.WorkQueueManager$Worker.run(WorkQueueManager.java(Compiled Code))
at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java(Compiled Code))
thanks again, I appreciate.
# 8
Ok, post the code for this method:
ApplicantInfoDao.insertCustomer()
Indicate which is line 50 of that file as well please. You should start digging into this yourself as well - that's where the error occurs, so whatever it is will be down to a null reference in your entity somewhere that it shouldn't be.
# 9
>>You should start digging into this yourself as well - that's where the error occurs, so
Sure... I have been digging in for days now. May be I am just failing to read between lines some where.
public class ApplicantInfoDao extends HibernateDaoSupport implements IApplicantInfoDao {
public void insertCustomer(ApplicantInfoForm appInfo) throws BusinessLogicException{
getHibernateTemplate().save(appInfo); // LINE 50
}
This is the code, that calls the method in the DAO
<<<<< ACTION CLASS >>>
public class updateDao extends Action {
ApplicantInfoDao applicantInfoDao;
public ApplicantInfoDao getApplicantInfoDao() {
return applicantInfoDao;
}
public void setApplicantInfoDao(ApplicantInfoDao applicantInfoDao) {
this.applicantInfoDao = applicantInfoDao;
}
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
HttpSession session = request.getSession(true);
try{
ApplicantInfoForm aForm = (ApplicantInfoForm)session.getAttribute("ApplicantForm");
getApplicantInfoDao().insertCustomer(aForm);
System.out.println("updated the database with serial value as :");
System.out.println(aForm.getQuotationNumber());
}
catch (Exception e) {
System.out.println(e.toString());
}
return mapping.findForward("Updated");
Thank you so much in advance, for your help.
# 10
the aForm, never is null.I am able to SOP the values from it for every single request. Thats why, I fail to understand where the NPE is coming from. aForm has values and I understand Hibernate is generating the serial Id as well (the alternate numbers in the SOP, after the insert show that). :-(
# 11
Make sure you've got the latest Oracle JDBC driver. Make sure that you've only got one copy of it as well (no ojdbc14.jar in the WEB-INF/lib directory for example).
Incidentally, the code you're posting does an e.toString() instead of an e.printStackTrace() - are you definitely looking at the latest code?
# 12
>>Make sure you've got the latest Oracle JDBC driver. Make sure that you've only got one copy of it as well (no ojdbc14.jar in the WEB-INF/lib directory for example).
oh yes. All the settings are fine. am using ojdbc14.jar. Earlier I had classes12/11/.. all of them in the path.Its all clean. With only one ojdbc14.jar.
>>Incidentally, the code you're posting does an e.toString() instead of an e.printStackTrace() - are you definitely looking at the latest code?
As a matter of fact, none of these e.printST() || e.getMessage()
methods print out anything.
Its only through the server logs, that I know it is the NPE
# 13
> oh yes. All the settings are fine. am using
> ojdbc14.jar. Earlier I had classes12/11/.. all of
> them in the path.Its all clean. With only one
> ojdbc14.jar.
Double and triple check this. I don't know what the problem is, but there are documented issues with out of date versions of the Oracle JDBC driver that cause an NPE in exactly that spot.
> As a matter of fact, none of these e.printST() ||
> e.getMessage()
> methods print out anything.
It doesn't help me if you show me code other than what you're actually running when you encounter the problem. Can you cut and paste with no modifications the code in question please.
# 14
>>but there are documented issues with out of date versions of the Oracle JDBC driver that
I could smell this somewhere, and I downloaded the R2 version of ojdbc14 and am using that as of now.
>>Can you cut and paste with no modifications the code in question please
The action classes
public class updateDao extends Action {
ApplicantInfoDao applicantInfoDao;
public ApplicantInfoDao getApplicantInfoDao() {
return applicantInfoDao;
}
public void setApplicantInfoDao(ApplicantInfoDao applicantInfoDao) {
this.applicantInfoDao = applicantInfoDao;
}
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
HttpSession session = request.getSession(true);
try{
ApplicantInfoForm aForm = (ApplicantInfoForm)session.getAttribute("ApplicantForm");
//aid.insertCustomer(aForm);
getApplicantInfoDao().insertCustomer(aForm);
System.out.println("updated the database with Serial value as :");
System.out.println(aForm.getSerial());
getApplicantInfoDao().getSessionFactory().close();
session.invalidate();
}
catch (Exception e) {
System.err.println();
e.printStackTrace();
}
return mapping.findForward("Updated");
}
}
The class which forwards control to the above given
public class ApplicantInfo extends Action {
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
ApplicantInfoForm appInfoForm = (ApplicantInfoForm)form;
HttpSession session = request.getSession(true);
session.setAttribute("ApplicantForm",appInfoForm);
//return mapping.findForward("driverInfo");
return mapping.findForward("Update");
}
}
The Hibernate Dao Support class
public class ApplicantInfoDao extends HibernateDaoSupport implements IApplicantInfoDao {
public void insertCustomer(QuoteBean quoteInfo)throws DataAccessLayerException,BusinessLogicException{
getHibernateTemplate().save(quoteInfo);
}
public void insertCustomer(ApplicantInfoBean appInfo) throws DataAccessLayerException,BusinessLogicException{
getHibernateTemplate().save(appInfo);
}
public void insertCustomer(VehicleInfoBean vehicleInfo)throws DataAccessLayerException,BusinessLogicException{
getHibernateTemplate().save(vehicleInfo);
}
public void insertCustomer(DriverInfoBean driverInfo)throws DataAccessLayerException,BusinessLogicException{
getHibernateTemplate().save(driverInfo);
}
public void insertCustomer(CoverageInfoBean coverageInfo) throws DataAccessLayerException,BusinessLogicException{
getHibernateTemplate().save(coverageInfo);
}
public void insertCustomer(QuotesForm quoteInfo)throws BusinessLogicException{
getHibernateTemplate().save(quoteInfo);
}
public void insertCustomer(ApplicantInfoForm appInfo) throws BusinessLogicException{
getHibernateTemplate().save(appInfo);
}
public void insertCustomer(VehicleForm vehicleInfo)throws BusinessLogicException{
getHibernateTemplate().save(vehicleInfo);
}
public void insertCustomer(DriversForm driverInfo)throws BusinessLogicException{
getHibernateTemplate().save(driverInfo);
}
public void insertCustomer(CoverageForm coverageInfo) throws BusinessLogicException{
getHibernateTemplate().save(coverageInfo);
/*if(true){
throw new BusinessLogicException();
}*/
}
public void closeAndClear(){
getHibernateTemplate().clear();
getHibernateTemplate().flush();
}
}
The IApplicant interface has nothing more than the methods used in the above given class.
# 15
I am using oracle 9 and the R2 version of ojdbc14, just in case.I sincerely appreciate your time and effort for helping me. Thanks again
# 16
Hey Dave.
Its solved now. Strangely, I had to change the statement cache size from 10 to 0.. Though the URLs given below suggest that a newer driver(as even you pointed out at some point) should solve this problem, I have tried with the 9.2.0.5 (earlier i was using the defaul one (the one with the installation), then I tried the 10gR2 and then the latest driver 9.2.0.5. However none of these drivers solved the problem.
But now, I need to figure out where all this change in the statement cache size will affect the actual product, where we expect to deal with rowsize of more than a couple of lakhs. Thanks for all your help and support. I appreciate.
http://forum.springframework.org/showthread.php?t=10221
http://forum.springframework.org/archive/index.php/t-10221.html
# 17
oopss.. both of 'em are the same URls basically. Heres the one for Hibernate http://forum.hibernate.org/viewtopic.php?t=934050