Hello,
        You invoke BeanUtils.copyProperties on two objects, it will copy
Only properties that are the same between two objects..
As I said, could you handle your lazyexception by simply building another
collection out of the collection returned by hibernate? 

Btw, sorry for my ignorance about that lazy exception, but what are you
Supposed to do when a lazy exception is thrown?

Apart from my ignorance of that exception, I suppose it's better to handle
That exception in your service layer, so you will give to the web layer
A 'proper' collection rather than let the web layer handle that...

HTH
        marco



-----Original Message-----
From: Tom Ziemer [mailto:[EMAIL PROTECTED] 
Sent: 30 November 2005 15:39
To: Struts Users Mailing List
Subject: Re: slightly [OT] Hibernate and domain objects in web apps

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]


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

Reply via email to