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".
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!
Joined: Oct 30, 2008
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.
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com
subject: Problem in running Hibernate Sample application