Win a copy of OCP Oracle Certified Professional Java SE 11 Programmer I Study Guide: Exam 1Z0-815 this week in the Programmer Certification 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 ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Paweł Baczyński
  • Piet Souris
  • Vijitha Kumara

"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!
 
Greenhorn
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).

Chris
 
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 ]
 
Onion rings are vegetable donuts. Taste this tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!