| Author |
[Help] Null Pointer Exception in session.flush() Hibernate
|
Fandy Akhmad
Ranch Hand
Joined: Nov 26, 2011
Posts: 32
|
|
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
Joined: Mar 24, 2008
Posts: 3670
|
|
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?
|
SCJP 5 | SCWCD 5
[How to ask questions] [Twitter]
|
 |
Fandy Akhmad
Ranch Hand
Joined: Nov 26, 2011
Posts: 32
|
|
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
Ranch Hand
Joined: Nov 09, 2011
Posts: 657
|
|
Between the lines
and
I don't see where session is initialized.
|
 |
Vijitha Kumara
Bartender
Joined: Mar 24, 2008
Posts: 3670
|
|
|
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
Joined: Nov 26, 2011
Posts: 32
|
|
Thanks for your help
It Works..!
I try to remove line code
and replace with
|
 |
 |
|
|
subject: [Help] Null Pointer Exception in session.flush() Hibernate
|
|
|