struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Peterus Greatus <>
Subject How do my Actions get to Hibernate so they can persist my objects?
Date Mon, 09 Mar 2009 00:07:26 GMT

I am hoping someone can paint a picture for me as I do not really understand
the relationship between Struts2 + Spring + Hibernate. The reason I know
about Spring is every book or tutorial I can find with Struts2 and
persistence uses Spring. 

Background is my last programming in Java was 9 years ago with Struts – I
really enjoyed it and now I’ve to write a new web app so I chose Struts2.
Over the past two weeks I’ve spent more time learning Hibernate, Ant,
something called Maven, I bought a Struts book that use Maven and now I’ve
to understand something called Spring!

I thought this was going to be easier than Struts 1 with JDBC and writing my
own SQL.
It’s not programming its learning frameworks!

Anyway back to my question. I understand Struts2 quite well now, I can make
forms and produce success pages. Everything is transient. I now need to add
some persistence so I am using Hibernate (as its seems to be the bees
knees). After much reading of a large book about Hibernate I understand how
that works….

What I don’t get is how my Struts2 action talks to Hibernate.
I've added a Listener to my web.xml for Hibernate, but not sure when that is
I have a HibernateUtil that creates a SessionFactory which I understand is
used for transactions with the database. I want that guy to start when my
web app is started in Tomcat so all I have to do is go to him to make a DB

But how do I get a session from the factory within a Struts2 Action? It
seems odd to put code into each Action to do this. I imagine people more
clever than I solved this problem.

I figure this is where Spring comes in with Inversion of Control or some
other concept I’ve started reading about.

I've read this guy
This PersonService object seems like a hokie solution. Do I make a Service
for each object I want to persist? Thats a bit mad. I have to define all of
these services in Spring too? I’m already defining a bunch of Hibernate
mapping xml file for each object I want persisted… I'm writing more XML than
Also how come I’m defining the database connection details in Spring when I
have them in my hibernate.cfg.xml ?
I think what is lacking is an explanation of why certain things are done the
way they are (it’s supposed to be a tutorial…for beginners). Even those
tutorial writing guys over at RoseIndia don't seem to have nailed this.

I understand Tomcat, Web Apps with Servlets & JSPs. Spring seems to wrap
itself around Hibernate. Tomcat somehow makes Spring go, which in turn does
the Hibernate bit. I don’t see how my Actions in Tomcat get to the database
via Hibernate any easier with Spring.

I read this guys post here So I’m
pretty certain I need to be using Spring. 

To me it seems like Spring is a pre-requisite for Java development. Maybe I
need to be drinking the Spring Kool-Aid.

Any help so I can get back to making my web app would be much appreciated.


View this message in context:
Sent from the Struts - User mailing list archive at

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message