• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Null pointer Exception when insert new record to database using struts2 and hibernate3

 
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Hello every one,
My problem is that , when i am insert a new record to database using struts2 and hibernate3 a null pointer exception is given because my database one id is generate when new record insert which is auto increment when insert new record null id pass and same time file upload to drive successful but record not insert into a Mysql 5.0.5 database my tomcat server gives exception is as follow:



My jsp is:



My struts.xml file is:


My hibernate.cfg.xml is:





My Action class is TenderAction.java




My bean class Tender.java is :


My DAO i.e. database connectivity TenderDAOImpl.java class is:



Please give me solution i am facing that problem from 3 days
Thank you
 
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The stack trace says the problem occurred on line 29 of TenderDAOImpl:


The code you've given us for that class shows a close brace on line 29. Either your code or your stack trace are out of date. Can you give us the current code/stack trace?
 
sudarshan jadhav
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you Joe Ess for reply,

In TenderDAOImpl.java i am add candition if (transaction != null) the stack trace or Apache tomcat 7.0 not gives any error but struts.xml file <result name="input"> tag gives same page with no error my dao changes and stack trace/Console is follows




i am past all my code previous post see that and my jar file see then attachement
lib-file.png
[Thumbnail for lib-file.png]
lib struts2 and hibernate3
 
Joe Ess
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

sudarshan jadhav wrote:



Never ever Ever EVER do this. If an exception occurs, you'll never know. At the very least, invoke e.printStackTrace().
I'm not sure what I'm supposed to derive from the image that you posted.



 
sudarshan jadhav
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you Joe Ess for reply,
I am write catch() code for exception handling but i am replace that code and write previous but exception is occured as:
 
Joe Ess
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You still haven't shown us what is on line 29 of TenderDAOImpl
 
sudarshan jadhav
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

com.ami.dao.TenderDAOImpl.saveUpdateTender(TenderDAOImpl.java:29)


joe My TenderDAOImpl.java class is as follow but exception occured at line 29 which transaction.rollback(); i know way error is occured because id which is auto generated when new record is
pass to session.saveOrUpdate(tender); the null id i.e. primary key is passed but when new record insert into database auto increment key is genrated that is reason but how can solve this problem

 
Joe Ess
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

sudarshan jadhav wrote:

com.ami.dao.TenderDAOImpl.saveUpdateTender(TenderDAOImpl.java:29)


joe My TenderDAOImpl.java class is as follow but exception occured at line 29 which transaction.rollback();



Then why doesn't transaction.rollback() appear in the stack trace? I still think you have the wrong line.
 
sudarshan jadhav
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Sorry Joe you are right actually some changes in my TenderDAOImpl class so line number 30 is exception occured.
Joe please explain me why this error is occured because same program logic use in that file create to drive not use and my post code drive create file logic use but whithout file create insert record successfully but Posted program not run and gives exception in line number 30
Please reply me.
 
Joe Ess
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

sudarshan jadhav wrote:
Joe please explain me why this error is occured



This is the third time I'll say it: you haven't shown us the code that corresponds to the error. We can't help you without that.
 
sudarshan jadhav
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thank you joe for reply,
already i am send to you my exception on jsp page not exception on tomcat console again i am paste jsp page exception and tomcat 7.0 console:
jsp page exception is:


Tomcat 7.0 console is:



 
Joe Ess
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Joe Ess wrote:

sudarshan jadhav wrote:
Joe please explain me why this error is occured



This is the third fourth time I'll say it: you haven't shown us the code that corresponds to the error. We can't help you without that.


 
sudarshan jadhav
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Joe i am post hole code but some changes into struts.xml file so that new runtime exception show on tomcat console is as follow but my hole code is same but only changes in xml :



My struts.xml is follow:


please please joe see my hole post with exception,java code , jsp and xml mapping file
 
Joe Ess
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This used to be a problem with the devmode flag (see here) but should be fixed. Are you using a recent version of Struts?
 
sudarshan jadhav
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you Joe firstly for reply,
i am using struts2.1.6 and hibernate 3.0 i am attaching jar image file with a previous post please see it is right jar file for that version
please reply me for null pointer exception in struts2 . I am setting id with default value but runtime exception is shown on console
 
Joe Ess
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you would have followed the link I posted earlier, you would see that the version of Struts with the devmode problem is 2.1.6, the same version you are running. I recommend you upgrade.
As for the null pointer exception, you STILL haven't shown us the code where the error takes place.
 
sudarshan jadhav
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you joe for link you have suggested to me , but how to upgrade or add that patch file to my jar file please reply me urgently.
 
Joe Ess
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
1. Download the current version of Struts
2. Replace the Struts jar and its dependencies in your project.
 
sudarshan jadhav
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Hello Joe still null pointer exception i am added new jar file which are shown me on post attachement file and error code is as:

See my struts.xml file is as:


please joe help me all other code are as previous i am post on it. please suggest some idea because my code right on lt is a any one mapping or jar file missing or not please tell me what is the reason to exception
 
sudarshan jadhav
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
sorry my jar file is as see attachement:
new-struts2.3.8-hibernate3.0-jar-file-list-in-my-application.png
[Thumbnail for new-struts2.3.8-hibernate3.0-jar-file-list-in-my-application.png]
new struts2 jar file added in my application
 
sudarshan jadhav
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Thank you Joe. my program is run and record insert into database with file upload at a drive. I am remove interceptor tag in struts.xml my record is inserted successfully
But suggest me for file upload 20mb (or file more then 20mb upto the maximum size allowed) to server drive and fileupload tag is required for struts.xml
Please joe reply me
 
reply
    Bookmark Topic Watch Topic
  • New Topic