Very informative - thanks, Ted.

-----Original Message-----
From: Ted Husted [mailto:[EMAIL PROTECTED] 
Sent: Sunday, August 10, 2003 3:13 PM
To: Struts Users Mailing List
Subject: Re: Has anyone used Hibernate with Struts?


There's a new Hibernate plugin example for Struts on the website now. I 
haven't switched over to that one myself yet, but I imagine that I might.

http://hibernate.bluemars.net/105.html

After from the convenience of using a PlugIn to initialized a hibernate, 
Struts and Hibernate don't need to interact at all. You should think in 
terms of using Hibernate to persist your Business Model. Struts works 
with your Business Model, and your Business Model works with Hibernate, 
but Struts and Hibernate don't need to know that each other exists. 
(Layers pattern.)

What I do now is define a String token for each of my business use 
cases. I then use that String as the ActionMapping attribute (same as 
the name by default). My Struts Action then passes the use-case name 
(attribute) and the data object (ActionForm) to a singleton that acts as 
my business facade. The facade returns a business response object. This 
is a rich transfer object that includes properties for data, messages, 
and so forth. The Action looks at what is returned, and dispatches to 
the view from there.

The use-case name is just a String (defined as a Static in one of my 
business classes), so that's simple to pass to my business classes. To 
let the ActionForm participate in the facade, it implements a very 
simple business interface and is passed under that interface than 
ActionForm or Object.

Behind the facade, the business layer takes care of storing and 
retrieving objects to Hibernate, or whatever. Struts doesn't know or 
care about Hibernate. It just knows what properties goes with which 
use-case and passes that to the facade.

Since the Struts validator uses the ActionMapping attribute as its 
form-name, the validations are then also keyed to the use-case. Ideally, 
I'd like my facade to apply the validations too, but I'm not quite there 
yet. =:(

The subtle point is that use-case names, data properties, and 
validations are defined by the facade as part of its API. Struts then 
adopts the use-case names as attributes, implements the data properties 
specified as an ActionForm, and implements the validations in the Struts 
validator. The same goes for the ActionForward names ("dispatcher 
tokens") used by the Actions. All this stuff is specified by the facade, 
and Struts just uses them. (Being scientists, it's important that we 
keep the cause and effect sorted-out.)

The other subtle point is that Struts really doesn't know anything about 
the business layer objects. The facade passes coarse-grained data 
transfer objects back and forth. Internally, my business layer uses 
fine-grained objects (as suggested by the Hibernate team), but Struts 
doesn't see any of that. Any data-conversion or property munging takes 
places behind the facade.

I also carry the use-case tokens as far back as I can, to hold 
everything together. For example, the use-case name is also used as a 
key into a map of Hibernate queries. To pull up the query for a 
use-case, I pass a component the same String that Struts used as the 
ActionForm/validator attribute. Again, neither Struts nor the Hibernate 
components own these String tokens. The business layer owns the use-case 
names (or "Commands"), and the other layers just use them.

-Ted.


David Friedman wrote:
> Dear Victor,
> 
> I'm in the same boat with Struts and Hibernate.  I found the Hibernate 
> 2.0 reference PDF 
> http://hibernate.bluemars.net/hib_docs/reference/pdf/hibernate_referen
> ce.pdf
> and the struts-hibernate example PlugIn (by Tedd Husted, at
> http://sourceforge.net/projects/struts under the name "hibernate") to be
> very helpful.  Let's just say that before finding that, my attempt at a
> PlugIn was VERY crude (though it DID work).
> 
> I'll be trying to get it to work for my site's member login feature 
> this weekend so I should be more help next week. :)
> 
> Regards,
> David
> 
> -----Original Message-----
> From: victor gusz [mailto:[EMAIL PROTECTED]
> Sent: Saturday, August 09, 2003 11:52 AM
> To: [EMAIL PROTECTED]
> Subject: Has anyone used Hibernate with Struts?
> 
> 
> Hi, Guys:
> 
> I want to learn Hibernate, Hibernate site does not
> seem to provide good examples. Has anyone have this
> kind simple running example for starters to follow?
> 
> 
> regards,
> 
> __________________________________
> Do you Yahoo!?
> Yahoo! SiteBuilder - Free, easy-to-use web site design software 
> http://sitebuilder.yahoo.com
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 
> 

-- 
Ted Husted,
   Junit in Action  - <http://www.manning.com/massol/>,
   Struts in Action - <http://husted.com/struts/book.html>,
   JSP Site Design  - <http://www.amazon.com/exec/obidos/ISBN=1861005512>.



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to