• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Problem using hibernate

 
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello friends,

I am having this problem while using hibernateTemplate to save the contents of an annotated POJO class into database using Hibernate. My application uses Spring to handle the services and Hibernate (org.springframework.orm.hibernate3.HibernateTemplate) to handle the database functionality. In my Data Access Object (DAO) class, I have a simple method which gets a VO (POJO) class and saves it to the database using hibernateTemplate.save(obj). The class is :



When the above method is run, a "null" is being printed on the console log and it is not being saved into database. There is no other error shown. There is no null values in the VO class as I've tried printing the values in it. In the spring applicationContext, I've created a bean for this class as :



The annotated VO class looks like :


I am running this application on apache tomcat 6 and MySQL database. Can you please help me identify problems in the code if any. Do you want me to put the log appearing in the console on application startup?
Thanks in advance.
 
Ranch Hand
Posts: 672
4
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Since you created new topic for this, lets continue the discussion here.. First, set show_sql to true, and tell us, whether you see an insert query in the console. It prints null in the console, means, when it prints null? when you check for hibernateTemplate.contains() or where?
Generally, if data is not saved in backend means, data is not flushed to the backend, what do get when you print hibernateTemplate.getFlushMode()?
 
Nitin Menon
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Prasad Krishnegowda wrote:Since you created new topic for this, lets continue the discussion here.. First, set show_sql to true, and tell us, whether you see an insert query in the console. It prints null in the console, means, when it prints null? when you check for hibernateTemplate.contains() or where?
Generally, if data is not saved in backend means, data is not flushed to the backend, what do get when you print hibernateTemplate.getFlushMode()?



it prints null on the console when it encounters the first hibernateTemplate method. I'll try both hibernateTemplate.getFlushMode() and also will set show_sql to true.
 
Nitin Menon
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Nitin Menon wrote:

Prasad Krishnegowda wrote:Since you created new topic for this, lets continue the discussion here.. First, set show_sql to true, and tell us, whether you see an insert query in the console. It prints null in the console, means, when it prints null? when you check for hibernateTemplate.contains() or where?
Generally, if data is not saved in backend means, data is not flushed to the backend, what do get when you print hibernateTemplate.getFlushMode()?



it prints null on the console when it encounters the first hibernateTemplate method. I'll try both hibernateTemplate.getFlushMode() and also will set show_sql to true.



I tried both of them. I dont know why nothing is getting printed there other than a "null".
The logs at the startup of the application are:


I hope there is nothing fishy in there.
 
Prasad Krishnegowda
Ranch Hand
Posts: 672
4
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
First make sure that, hibernateTemplate is not null.. If its null, use the ClassPathXmlApplicationContext of spring and get the bean.. and try ivoking the method using this bean..
 
Nitin Menon
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Prasad Krishnegowda wrote:First make sure that, hibernateTemplate is not null.. If its null, use the ClassPathXmlApplicationContext of spring and get the bean.. and try ivoking the method using this bean..



Can you make that little more clear? What exactly should I do? I am not too good at the configuration part.
 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Where are you defining which methods are transactional. My first guess is that it is not transactional, and Hibernate requires a transaction. My guess would then be that there is no Session in the template to run the data access code, and it is throwing a DataAccessException which is an unchecked exception.

Mark
 
Prasad Krishnegowda
Ranch Hand
Posts: 672
4
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Also, in catch block, instead of System.out.println(e.getMessage()); print the stackTrace and can you paste that stack trace here, so that we can get to know, what is throwing an NullPointerException..
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic