This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Object Relational Mapping and the fly likes session null Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "session null" Watch "session null" New topic
Author

session null

Samanthi perera
Ranch Hand

Joined: Jan 08, 2010
Posts: 510
this is my Contact.java


this is contact.hbm.xml


this is config.xml


this is main class



this is the output



that means session doesn't create.
Where is the Error?

I have already added hibernate3.jar,mysql-connector-java-3.0.16-ga-bin.jar and commons-logging-1.0.4.jar to Build path
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Turn up logging to debug level so you can see what's wrong.
Samanthi perera
Ranch Hand

Joined: Jan 08, 2010
Posts: 510
I place a Debug pointer at this line
SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();
session =sessionFactory.openSession();

and then press F6.
this is i got.
I can't understand what happen?



Samanthi perera
Ranch Hand

Joined: Jan 08, 2010
Posts: 510
Still I am unable to fine where is the Error?
Samanthi perera
Ranch Hand

Joined: Jan 08, 2010
Posts: 510


I am using Eclips ,So i think it is not need to add mysql connector to CLASSPATH ?
I already added mysql-connector.jar as a library.
Jose Ayerdis
Ranch Hand

Joined: Sep 14, 2008
Posts: 30
i think that it might not finding the hibernate.cfg the you have it on your root source package??... can you handle over a eclipse proyect so i can see if i get the same error??
Samanthi perera
Ranch Hand

Joined: Jan 08, 2010
Posts: 510
Here is my folder stucture
http://asliyanage.blogspot.com/2010/01/blog-post.html
Jose Ayerdis
Ranch Hand

Joined: Sep 14, 2008
Posts: 30
try forcing the path file with an absolute path let see what happens something like this

Samanthi perera
Ranch Hand

Joined: Jan 08, 2010
Posts: 510
here is my file path


when i attempt to use this it says invalid escap sequence



Here is a Scrennshot
http://asliyanage.blogspot.com/2010/01/blog-post_24.html
Jose Ayerdis
Ranch Hand

Joined: Sep 14, 2008
Posts: 30
try using the double backslash

D:\\PROJECT\\Gwt-eclips\\hibernateexample\\src\\roseindia\\tutorial\\hibernate\\hibernate.cfg.xml
Mark E Hansen
Ranch Hand

Joined: Apr 01, 2009
Posts: 643
Jose Ayerdis wrote:try using the double backslash

D:\\PROJECT\\Gwt-eclips\\hibernateexample\\src\\roseindia\\tutorial\\hibernate\\hibernate.cfg.xml

Or forward slashes. I always use forward slashes for file separators in Java source, regardless of the platform on which the application should run.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Or File.pathSeparator.
Christian Dillinger
Ranch Hand

Joined: Jul 20, 2009
Posts: 188
Put hibernate.cfg.xml into your src-folder and Hibernate will find it.
Samanthi perera
Ranch Hand

Joined: Jan 08, 2010
Posts: 510
I change my class now


here still problem



Christian Dillinger
Ranch Hand

Joined: Jul 20, 2009
Posts: 188
It's useless to get a File-Object if you don't use ist... Take a look into the Hibernate api-doc, where to put the path to the config-file. And again: just put it into the src-Folder and it works. Hibernate looks for a file named hibernate.cfg.xml there. You only have to configure the path if you don't put into the "root"-folder.
Samanthi perera
Ranch Hand

Joined: Jan 08, 2010
Posts: 510
I am using eclips.How to set path in eclips
Christian Dillinger
Ranch Hand

Joined: Jul 20, 2009
Posts: 188
Do you read the answers posted here?!?

If you put hibernate.cfg.xml into the src-folder and not into any package, Hibernate will find it. If you want to put into a special package take a look into the API and find out that that you have to use new Configuration().configure(SET THE RIGHT FILE *HERE*)....
Samanthi perera
Ranch Hand

Joined: Jan 08, 2010
Posts: 510
ok
I put it.
now path of config file is
D:\PROJECT\Gwt-eclips\hibernateexample\src\hibernate.cfg.xml

here is a Screenshot
http://asliyanage.blogspot.com/2010/01/blog-post_25.html



Still i got this error

Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

What happens on line 37 of the class FirstExample?


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Samanthi perera
Ranch Hand

Joined: Jan 08, 2010
Posts: 510
session.flush();
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

So you have no session, in which case you will have a stack trace explaining why (assuming you are running the code you have posted above).
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: session null
 
Similar Threads
Could not parse configuration: /hibernate.cfg.xml
org.hibernate.MappingException: table refers to an unmapped class
Newbie got stuck in Hibernate "Hello World"
org.hibernate.exception.GenericJDBCException
Exception in ClassFormatError: Absent Code attribute