Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Doubt in Integrating Hibernate with Springframework

 
Siddharth Bhargava
Ranch Hand
Posts: 280
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,
I am using Hibernate for persistence and I am using SimpleFormController in springmvc. I am developing a simple application to register a user. In my springconfiguration file I am configuring the properties as follows:




My doubt is that do I need to configure the hibernate properties :
hibernate.connection.url
hibernate.connection.driver_class
hibernate.connection.username
hibernate.connection.password

in
<property name="hibernateProperties">

</property>


as they are already configured in the dataSource property


Which one will be used. Please clear my concepts.
Thanks
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you are setting the dataSource of the LocalSessionFactoryBean, then you don't need to set Hibernate's properties. You can set both, but the dataSource settings will override Hibernate's properties. To avoid confusion, you'd better not use Hibernate's properties in this case.
 
Siddharth Bhargava
Ranch Hand
Posts: 280
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot for your help.
 
Siddharth Bhargava
Ranch Hand
Posts: 280
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,
I am using HibernateDaoSupport class for persistence in spring framework application.



But I am getting a NullPointerException in this line :

getHibernateTemplate().save(user);


Also where do I wire in my hibernateTemplate if I want to use my own hibernateTemplate which I have written in xml.

Please do help me
Thanks in advance.
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
All details can be found here
 
Siddharth Bhargava
Ranch Hand
Posts: 280
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I read it already. It provides information about HibernaterTemplate not HiberDaoSupport. Please tell me why I am getting NullPointerException and where do i set the getHibernateTemplate().
Thanks
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You need to set the sessionFactory like this :


It will automatically create a new HibernateTemplate, so you won't get a NullPointerException anymore.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic