Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem in running Hibernate Sample application

 
Aman Singh
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Experts,
I am trying to run a sample Hibernate application from www.roseindia.com. After many tries I couldn't get it to run. Everytime I try to run it, I am getting a "Exception in thread "main" java.lang.NullPointerException".

Can someone help me out with this


 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just a word of warning, the roseindia tutorials are not very good.

As with any NullPointerException there will be a line number telling you where it occured. What happens on that line?
 
Aman Singh
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Paul,
Thanks for your quick reply. You are very right, Roseindia tutorials are always full of bugs. For beginners, there aren't any details hibernate sample applications.

I am getting an error on line 34, which is session.flush();

Is it because we aren't able to build the session in the first place?

Regards
 
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper
Posts: 4968
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yeah, I'm not sure if you need to be flushing and closing that session on your first trial example. I'd also say that openSession, as opposed to using getSession, might lead to more problems than it would solve.

I've put together some little tutorials from my book on Hibernate and made them available on my website. They've been tested pretty thoroughly, and if the roseindia tutorials aren't doing it, might I be so humble as to suggest you might take a look:
Getting Started with Hibernate

Here's an example that I often use in setting up and vailidating a Hibernate configuration:


Okay, that's alot of code to throw out here without an explaination, but really, if you want to see what Hibernate is doing, and where the work really happens, look here:


Notice how the session is obtained, a transaction is started, a User is created, the session saves the User, and then the transaction is committed? That's really the key to Hibernate working.

Also notice that in this little example, there's no need to flush or close the session. Sure, once you start deploying a banking application, get those method calls in there in the right spots, but really, why confuse the issue when you just want something to work? Get the basics down, and the more advanced stuff will come very naturally.

Best of luck!

-Cameron McKenzie
 
Aman Singh
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Cameron,

I must say , One of the very good explanation :-) for a java newbie like me.

I made it to work, dont know how :-)

I did look at your tutorial while googling it, It is very informative. I didnt try it because I dont have the slightest idea of annotations or what exactly they are.







 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic