Khangharoth

September 29, 2009

FrameWork: Spring-JPA-Hibernate (Annoation Based)

Filed under: Architecture,Java,JEE — khangharoth @ 4:56 pm

This skeleton web framework I wrote for Quarks , as they wanted a core framework on top of which they can build the applications.

As I had a luxury to design a Framework from scratch and so decided with these technologies.This dev stack is now becoming a vary dominant framework or to say in developers words “The next Popular Stack”.

Testing env I have used in this framework is TestNg , which I feel is much more suited to present day testing needs than our old JUnit(even after realese of Junit 4).

And with JDK 5+ , Spring 2.5+ which give support for Annoatations , you can have a very Simple yet very powerful framework to work with.So with this what we have is

  • Spring as a Application Framework
  • JPA as Persistence Framework (Hibernate as JPA impl)
  • Annotation based Transactional Control.
  • Spring Dependency injection with Annotation.
  • Spring MVC : This can be changed if you want to use something else.
  • Annotation based Validation framework.

These all elements give us enough power to create a generic and robust framework ,which can be customized for various needs.

Now let’s get to the actual work ……

Core Design Principle : The whole framework is desigend in Layers.Each Layer can only be called by layer above it and no skip hierarcy call’s are allowed.

Various Layers are

  • Web : Comprises of Spring MVC & JSP , this is due to the fact that most developer in quarks are quite familiar with JSp and so we wanted to start with this.Although I am not really happy with technology choice and wanted to have GWT or Flex based GUI.
  • Delegate : This is logical seperation between Web(Front End) and Service (back End).If you think that GWT or you something else suits you then this is the place where you should take a detour.
  • Service : Spring based beans, annotation based Dependency & Transaction management.
  • DAO : Db access layer , based on JPA and using hibernate as Persistence provider.
  • Persistence Domain model : Java Beans on lines of JPA Entities.

So the principle is that a layer can only call layer below it so in this Web —-> Delegate and any call direct to say services or DAO’s should be discourged.

Another way to see this is that if we just delete a particular Layer then code below it should compile just as fine without any problem.

I wanted the package structure to reinforce this idea  .Also its easier for a new person to see as how the packages are organized . The package structure is

  • com.quarks.a.web.controller
  • com.quarks.b.delegate
  • com.quarks.c.service
  • com.quarks.d.dao
  • com.quarks.e.persistence

Used a,b,c,d,e so that packages are shown in order in project view and aslo it gives clear idea of dependency in project.

Now looking at this I can easily say that DAO is only dependent on persistence pacakge.

Note : Still in edit , I’ll upload code as well . Please do give your valuable opinion about how can we have a Generic framework on this Dev Stack .

Create a free website or blog at WordPress.com.