• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

[Help] Null Pointer Exception in session.flush() Hibernate

 
Fandy Akhmad
Ranch Hand
Posts: 32
Java Linux MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear All masters Java..

I learn Hibernate Framework, and try made simple application to insert data into Database.
I get error like this :

Exception in thread "main" java.lang.NullPointerException
at com.fandezign.training.hibernate.TestHibernate.main(TestHibernate.java:45)


And line 45 is pointing to session.flush(); statement.

Here is my code :



I hope all master's help and guidance.

Thank you.
 
Vijitha Kumara
Bartender
Posts: 3913
9
Chrome Fedora Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the CodeRanch!

Do you have any other code in the same file? Given is less than 45 lines of code... And do you get the record in the DB after running the code?
 
Fandy Akhmad
Ranch Hand
Posts: 32
Java Linux MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello, thanks for your respond

I try to add condition like this in finally block.


And problem solved. But new problem shown and many error.
This is error code :


And you may want to see my Hibernate and POJO file.

Here is my User.java


Here is my hibernate.cfg.xml


Here is my User.hbm.xml


Here is my TestHibernate.java file



Please help me,..
Thanks before...
 
James Boswell
Bartender
Posts: 1051
5
Chrome Eclipse IDE Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Between the lines

and


I don't see where session is initialized.
 
Vijitha Kumara
Bartender
Posts: 3913
9
Chrome Fedora Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There's no errors in the snippet of the log you posted. And you begin the transaction after the save() is executed? I suggest you read the getting started guide in the documentation here.
 
Fandy Akhmad
Ranch Hand
Posts: 32
Java Linux MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your help

It Works..!

I try to remove line code

and replace with




 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic