• 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

do we need to integrate spring with hibernate or it can be one code calling another?

 
Ranch Hand
Posts: 2929
13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why is spring hibernate integration needed. Why cant it be simply one code calling another i.e Spring code calling hibernate code.

thanks
 
Saloon Keeper
Posts: 27819
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Spring Hibernate is part of Spring Data, which is the data-persistence component of Spring. You can use Spring without Spring Hibernate. But Spring Data has significant benefits, such as the fact that it automatically obtains and cleans up persistence resources, normalizes error handling and can provide declarative transaction management.

So very often I use Spring specifically so I can use Spring Data.
 
Monica Shiralkar
Ranch Hand
Posts: 2929
13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Spring Hibernate is part of Spring Data, which is the data-persistence component of Spring



Thanks. I actually meant integrating Spring with Hibernate (Not 'Spring Data'). E.g Suppose I have an application which has to use Spring MVC,Hibernate (Not Spring data). Now can it be just like Spring MVC code calling the Hibernate code or it has to be integrated?
 
Ranch Hand
Posts: 624
9
BSD Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am not very sure, but I think Hibernate cannot be called from Spring MVC. It has to be integrated in Spring.

In my application I have put Hibernate properties in Servlet-context.XML and I take this as integration.

I do not really know whether Hibernate can be called from Spring MVC.
 
Monica Shiralkar
Ranch Hand
Posts: 2929
13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I am not very sure, but I think Hibernate cannot be called from Spring MVC

I do not really know whether Hibernate can be called from Spring MVC.



Thanks but I could not understand this in your reply.

I thought any code can call any other code. I have successfully run Spring MVC with hibernate as shown below in the email but what I have done are the below 3 steps:

Step 1

Write Spring MVC code.

Step 2

Write Hibernate code.

Step 3

Call Hibernate code from the Spring code.

I called the below code from the Spring MVC and it worked fine:




But I fail to understand that if I can run the code successfully like above then why is Spring Hibernate integration needed?


 
Tapas Chand
Ranch Hand
Posts: 624
9
BSD Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Again I would say I am not sure whether I am correct, but I think you have answered your question yourself through the code snippet.

In the snippet you have instantiated all Hibernate classes yourself, thus skipping the most important feature of Spring, i.e. Dependency Injection.

If you would have integrated Hibernate in Spring, it would have been the job of Spring to inject the dependencies.
 
Monica Shiralkar
Ranch Hand
Posts: 2929
13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

In the snippet you have instantiated all Hibernate classes yourself, thus skipping the most important feature of Spring, i.e. Dependency Injection.

If you would have integrated Hibernate in Spring, it would have been the job of Spring to inject the dependencies.



But I can simply added the beans in ShoppingCart-servlet.xml and objects would have been injected from there. For this there is no integration required.

What you have said is correct about usage of dependencies using Spring IOC but for that where is any integration needed?
 
Tapas Chand
Ranch Hand
Posts: 624
9
BSD Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Oh now I probably understand your question. I am sorry for my previous replies.

So with Spring-Hibernate integration you get HibernateTemplate.
Thus you save a lot of code.
Your total code snippet can be replaced by just this.

Let us wait for some experienced guys to tell some more advantages of Spring-Hibernate integration.
 
Monica Shiralkar
Ranch Hand
Posts: 2929
13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks. so one of the reasons for spring hibernate integration is that we can use hibernate template.
reply
    Bookmark Topic Watch Topic
  • New Topic