Win a copy of 97 Things Every Java Programmer Should Know this week in the Java in General forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

session.flush(); gives null

 
Ranch Hand
Posts: 1325
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
this is my hibernate.cfg.xml code



this is my Contact,java code


this is my contact.hbm.xml code


this is my test class

in the test class session.flush(); gives null
here is the error
 
Ranch Hand
Posts: 210
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Quite a few things..

1. Create a Transaction and save your entity inside that transaction.
2. Check to see if you got any exception while building the session factory...i.e. any exception on the console before this error.

it is possible that the creation of your sessionFactory and session failed(ie and error in line 21), and your session is null, hence giving a null pointer...
 
shawn peter
Ranch Hand
Posts: 1325
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
but if i comment the flush and close it gives this
 
shawn peter
Ranch Hand
Posts: 1325
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
anyway how to save this in a transaction?
 
shawn peter
Ranch Hand
Posts: 1325
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i only add the hibernate3.jar and mysql-connector-java-3.1.6-bin.jar.ithink it is enough.
 
Rahul Babbar
Ranch Hand
Posts: 210
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

aruna sameera wrote:but if i comment the flush and close it gives this


Add the commons-logging.jar to your application classpath.

You need to save the entities in a Transaction like

Transaction tx = session.beginTransaction();
// populate and save your entity.
tx.commit();
// if some exception occurs, check if the transaction is Active, if it is, do a tx.rollback();


Please do a 'google' for some hibernate tutorials, go through them for proper understanding.
 
shawn peter
Ranch Hand
Posts: 1325
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i change my test class to this


then error is
 
Rahul Babbar
Ranch Hand
Posts: 210
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

aruna sameera wrote:i change my test class to this



clearly it says that your hibernate.cfg.xml file is not found. Do you have such a file. If yes, where is it?
Please go through some simple hibernate tutorial on the net..
 
author and cow tipper
Posts: 5000
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Indeed, it looks like it's the location of the hibernate.cfg.xml file that's at issue.

People often put it next to a HibernateUtil class or in a package folder. The root of your source folder should be good enough.

Here's a little tutorial on setting up Hibernate that might be helpful. Just get something simple started and working, and progress from there.

Getting Started with Hibernate


-Cameron McKenzie
 
I don't get it. A whale wearing overalls? How does that even work? It's like a tiny ad wearing overalls.
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic