aspose file tools*
The moose likes Object Relational Mapping and the fly likes [Help] Null Pointer Exception in session.flush() Hibernate Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "[Help] Null Pointer Exception in session.flush() Hibernate" Watch "[Help] Null Pointer Exception in session.flush() Hibernate" New topic
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: 3829

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
Bartender

Joined: Nov 09, 2011
Posts: 1021
    
    5

Between the lines

and


I don't see where session is initialized.
Vijitha Kumara
Bartender

Joined: Mar 24, 2008
Posts: 3829

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




 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: [Help] Null Pointer Exception in session.flush() Hibernate