Win a copy of TensorFlow 2.0 in Action this week in the Artificial Intelligence and Machine Learning forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Liutauras Vilda
  • Paul Clapham
  • Bear Bibeault
  • Jeanne Boyarsky
  • Ron McLeod
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Jj Roberts
  • Stephan van Hulst
  • Carey Brown
  • salvin francis
  • Scott Selikoff
  • fred rosenberger

"Many WARs in one EAR" or "Code organization with Spring/Hibernate"

Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there!

I wonder, what is the proper code organization with Spring, when I have one EAR with numerous WARs inside, and all these WARs suppose to use Hibernate, and any of WARs can use any of Hibernate's mapping POJOs.
So it looks like in this EAR we need to have one "business logic", which all WARs will use.
How this should looks like? What are the best practicies?

I saw different example when using Spring+Hibernate for one Web Application (WAR), but not for numerous WARs in one EAR.

To clarify a bit more -- I am interested where Spring, Hibernate's files need to be placed. How Spring need to be "called" (with one WAR we just put everything into it's WEB-INF)... and all these things.
Any help or advice, or even link - appreciated, thank you!
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've not jumped onto the Spring bandwagon yet(only out of lack of time to get comfy in a new architecture), but heres my theory. Spring uses IoC(Inversion of Control), or the "let me create the objects, so you don't have to" theory. From my understanding of what i've read in the past, Spring can use two different types of factories to manage those beans, Prototype and Singleton. Doing some lookups on Google, I see that Springs default is to create Singleton objects(one per JVM). Just by using the defaults, Spring will create one SessionFactory for you which will be used by all the different threads. The only thing you need to worry about would be thread safety on all the other objects that you have designed yourself. Spring is just a cultivated product of best use cases(I probably need to bite the bullet and catch up).

Olexiy Prokhorenko
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Honestly speaking, my question was primary of how to organize the code. Where to place Spring's config, etc.
At the moment I found a solution of putting everything in JAR (Spring+Hibernate configs), libraries directly into EAR, and all my WARs in this EAR are able to work with Spring/Hibernate, however, this will require to force Ant to generate proper Class-Path for their manifests.

This is what I see. May be there is more elegant solution - but I was not able to find it yet.

What also I noticed, is that once each of WARs will start they both will use Springs config from JAR and this will force to create one Hibernate Session Factories for each of WAR! As I can understand it happens because each of WARs are started in separated JVM. Not sure how JBoss/Tomcat is doing this. But while I can keep only ONE copy of all configs in a one place I do not care if each of WARs will require it's own session factory. Besides, this makes sense.
[ July 20, 2005: Message edited by: Olexiy Prokhorenko ]
That's my roommate. He's kinda weird, but he always pays his half of the rent. And he gave me this tiny ad:
the value of filler advertising in 2020
    Bookmark Topic Watch Topic
  • New Topic