wood burning stoves 2.0*
The moose likes Struts and the fly likes Null pointer Exception when insert new record to database using struts2 and hibernate3 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Null pointer Exception when insert new record to database using struts2 and hibernate3" Watch "Null pointer Exception when insert new record to database using struts2 and hibernate3" New topic
Author

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

sudarshan jadhav
Ranch Hand

Joined: May 28, 2012
Posts: 42

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
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8836
    
    7

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?


"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
sudarshan jadhav
Ranch Hand

Joined: May 28, 2012
Posts: 42
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



[Thumbnail for lib file.png]

Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8836
    
    7

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

Joined: May 28, 2012
Posts: 42
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

Joined: Oct 29, 2001
Posts: 8836
    
    7

You still haven't shown us what is on line 29 of TenderDAOImpl
sudarshan jadhav
Ranch Hand

Joined: May 28, 2012
Posts: 42
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

Joined: Oct 29, 2001
Posts: 8836
    
    7

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

Joined: May 28, 2012
Posts: 42

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

Joined: Oct 29, 2001
Posts: 8836
    
    7

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

Joined: May 28, 2012
Posts: 42
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

Joined: Oct 29, 2001
Posts: 8836
    
    7

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

Joined: May 28, 2012
Posts: 42
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

Joined: Oct 29, 2001
Posts: 8836
    
    7

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

Joined: May 28, 2012
Posts: 42
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

Joined: Oct 29, 2001
Posts: 8836
    
    7

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

Joined: May 28, 2012
Posts: 42
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

Joined: Oct 29, 2001
Posts: 8836
    
    7

1. Download the current version of Struts
2. Replace the Struts jar and its dependencies in your project.
sudarshan jadhav
Ranch Hand

Joined: May 28, 2012
Posts: 42

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

Joined: May 28, 2012
Posts: 42
sorry my jar file is as see attachement:



[Thumbnail for new struts2.3.8 & hibernate3.0 jar file list in my application.png]

sudarshan jadhav
Ranch Hand

Joined: May 28, 2012
Posts: 42

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
 
wood burning stoves
 
subject: Null pointer Exception when insert new record to database using struts2 and hibernate3
 
Similar Threads
The requested list key 'names' could not be resolved as a collection/array/map/enumeration/iterator
Struts2 Helloworld Problem
Struts2:Action-validation.xml
Problem to save select tag value in struts2
strtus 2 application error