Win a copy of Java Mock Exams (software) this week in the Programmer Certification (OCPJP) forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Is this right way to Initiaize Hibernate configuration?

 
Kishor Joshi
Ranch Hand
Posts: 674
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there

I am designing a web application using Spring+Hibernate web application.

I am injecting these property in each bean I Intialize here is a example of one bean


I am using this hibernatePropertis configuration in many beans in Spring is this right approach to use Hibernate in Spring?

Thanks
 
Mark Spritzler
ranger
Sheriff
Posts: 17309
11
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No. You should only create one SessionFactory/EntitnyManagerFactory for your entire application. And you "registerEmployeeBean" Is not of type LocalSessionFactoryBean.

In A Spring Application you use a layered approach. Service layer for your business use case code and transaction demarcation at methods level. Repository Layer that stores your queries to run. And then there is the SessionFactory underneath. The sessionFactory gets injected into your repository classes. So one bean for sessionFactory and one bean per repository class with dependency injection injecting the sessionFactory into the repository classes. Then the repository classes are injected into the Service layer classes.

Mark
 
Kishor Joshi
Ranch Hand
Posts: 674
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@Mark

Thanks
 
Happiness is not a goal ... it's a by-product of a life well lived - Eleanor Roosevelt. Tiny ad:
the new thread boost feature: great for the advertiser and smooth for the coderanch user
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!