Tom

Basically the initialization occurs in the DAO and then passes back a list
of the requested objects.  I try to limit what dom objects I am sending back
so i only have to initialize a couple of branches occasionally.

I have thought about having a layer that is specific to the view where the
objects that are realted to what is being returned to the page.  The dom
objects that are needed are returned in a Map.  Then some sort of Factory
runs through the map and populates the View objects.  There may even be a
way to do this using Springs session factories.  That might limit the DTO
layer to one or two classes?

I have also been wrestling with the dto concept.  I haven't really seen a
solution yet that addresses what you are describing, other than using some
sort of dto.  Perhaps EJB3 addresses this in an elegant way but I haven't
researched that yet.  The use case you described where you have a rich
client communicating with the app seems to highlight this issue.  Sorry I
don't have any real answer for you.

Matt
On 11/30/05, Tom Ziemer <[EMAIL PROTECTED]> wrote:
>
> Hi,
>
> @Matt:
> thanks for your elaborate answer. My setup is a lot like yours: Spring
> manages the business objects and the DAOs. My problem is this:
>
> Struts->Business layer->HibernateDAO->Database will return a hibernate
> proxy of my dom object. I have to load all objects lazily, because our
> db has got a very hierarchical layout. This in turn means, that I cannot
>   use Hibernate.initialize on all collections, because it would be to
> expensive. Thus, I return an object, which is partially loaded - if my
> action accesses an attribute, which has not been initialized, I'll have
> to deal with a LazyInitializationExceptions, which, IMO, is bad.
>
> Apart from that, I'd like to ask, how you deal with lazy loading in
> general. Do you always return "complete", that is fully initialized
> objects? If not, how do you reflect this in your business layer? Will
> there be multiple methods for each object, depending on the number of
> collections that need to be initialized?
>
> @Marco
> again, thank you for your reply. My problem with DTOs is, that I expect
> to have about 150 dom objects, which would result in 150 DTOs. These are
> objects that I actually do not need - it'll just decrease performance.
> But unfortunately I do see an alternative to DTOs so far, so in case
> nobody else comes up with a brilliant idea, I guess I'll have to
> implement it that way.
>
> BTW: Is it possible to use BeanUtils to copy entire beans or will I have
> to use copy() on each property? Are DynaBeans (beanUtils) an alternative?
>
> Thanks,
> Tom
>
> Matt Morton wrote:
> > Hi Tom
> >
> > In our app we are using pattern where Struts calls a method from what I
> call
> > a service layer object.  Then the service layer calls the dao interface.
> > Then there is an implementation of the dao for Hibernate.  So the call
> stack
> > is something like:
> >
> > Struts Action -> ServiceManager.getSomeObject(Integer id) -> DAO.get
> (Integer
> > id) -> return Object
> >
> >  The service layer are actually Spring beans.  These beans are bound to
> the
> > dao's in the Spring appContext.  I am also using Spring to manage the
> Struts
> > actions.
> >
> > I have always wrestled with the DTO question.  I guess I haven't seen
> the
> > need for it while using Spring and Hibernate.  I have also created
> objects
> > that are specific to the view object (like a set of menu links) that is
> > being created dynamically and then populated that with the domain
> objects
> > values that were needed.   This latter solution is more like a poor mans
> (in
> > regards too time) JSF.
> >
> > With regards to the LazyLoading issues for collections that reference
> other
> > domain objects I usually use the Hibernate.initialize(Object)
> method.  It
> > will then go through and load the objects in the collection that are
> > necessary for what domain object you are using.  Then send the object
> back
> > to the action to be manipulated as necessary.
> >
> > Probably not perfect but seems to provide the flexibility we need.  I am
> > interested to know what others are doing too.
> >
> > Hope that helps.
> >
> > Matt Morton
> >
> > On 11/30/05, Tom Ziemer <[EMAIL PROTECTED]> wrote:
> >
> >>Hi,
> >>
> >>I have got a little problem with Hibernate - well actually it is only
> >>partially related to it:
> >>
> >>My app uses Spring + Hibernate (lazy loading), but should I return the
> >>value beans (dom) from Hibernate to my Struts actions? If I do this, I'd
> >>have to deal with LazyInitializationExceptions for collections that have
> >>been lazy-loaded. In my opinion, this would be a horrible design because
> >>the view would have to know about the data access tier. On the other
> >>hand, I've read, that "DTOs are evil" - but how can I solve this problem
> >>without DTOs?
> >>
> >>I am sure, lots of you are using
> >>Hibernate/{YOUR_LIST_OF_OTHER_GREAT_FRAMEWORKS_HERE}/Struts and I'd be
> >>grateful for any help.
> >>
> >>Thanks,
> >>Tom
> >>
> >>---------------------------------------------------------------------
> >>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