• 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

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

 
Ranch Hand
Posts: 32
MySQL Database Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Bartender
Posts: 4116
72
Mac TypeScript Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
MySQL Database Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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...
 
Bartender
Posts: 1051
5
Hibernate Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Between the lines

and


I don't see where session is initialized.
 
Vijitha Kumara
Bartender
Posts: 4116
72
Mac TypeScript Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
MySQL Database Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for your help

It Works..!

I try to remove line code

and replace with




 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic