File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Soft Skills: The software developer's life manual this week in the Jobs Discussion forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem using hibernate

 
Nitin Menon
Ranch Hand
Posts: 87
  • 0
  • Mark post as helpful
  • send pies
  • 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.
 
Prasad Krishnegowda
Ranch Hand
Posts: 665
4
Eclipse IDE Java Spring
  • 0
  • Mark post as helpful
  • send pies
  • 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: 87
  • 0
  • Mark post as helpful
  • send pies
  • 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: 87
  • 0
  • Mark post as helpful
  • send pies
  • 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: 665
4
Eclipse IDE Java Spring
  • 0
  • Mark post as helpful
  • send pies
  • 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: 87
  • 0
  • Mark post as helpful
  • send pies
  • 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.
 
Mark Spritzler
ranger
Sheriff
Posts: 17276
6
IntelliJ IDE Mac Spring
  • 0
  • Mark post as helpful
  • send pies
  • 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: 665
4
Eclipse IDE Java Spring
  • 0
  • Mark post as helpful
  • send pies
  • 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..
 
Consider Paul's rocket mass heater.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic