nodje wrote:
I'm using OpenSessionInViewFilter, and any lazy loading is working in my apps (except some toString() that calls apache ToStringBuilder.reflectionToString which crashes lazy init. sometimes)
CGLIB is deep voodoo for me, but I suspect that using reflection on a proxy might very well lead to disaster. I also use the commons-lang builders, but I never use the reflection builders, I always specify which fields I want to use manually.
Quote:
But when using BeanUtils.copyproperties(DTO, persistentObject) we end up with uninitialized part of the graph object referenced in the DTO.
When Velocity do a !$DTO.persistentObject.field1 it crashes.
I must admit this doesn't seems to always be the case.
So it probably should work.
Shouldn't you do BeanUtils.copyproperties(DTO.getPersistentObject(), persistentObject) instead, if you attach the persistent object as a property in the DTO?
Quote:
As for transaction, I don't think there's any difference between lazy loads in view or in Action transaction wise.
In principle no. But the danger is that in an Action you can start another transaction after you have lazy loaded something outside a hibernate transaction, leading to problems explained in point #2 in my above post. When lazy loading in the view, you can be sure that it will be the last database access before the connection is returned to the pool and any non-finished transaction (such as the lazy load) rollbacked.
Quote:
But isn't it a bad practice to reference part of object graph in the DTO instead of copying only necessary data??
Well, doesn't that sort of defeat the purpose of using a DTO in the first place?