views:

149

answers:

2

When a system has N tiers, and when using an ORM, how do you send loaded entities across the tiers ?

Do you use DTO ?

When DTO are not used and the entities are directly sent, how do you protect againt the uninitialized lazy loaded relationship errors ?

Note : this is not a "should N tiers be used ?" question. I assume that the system already has N tiers.

+1  A: 

Well I don't know if there is a better way, but when we use Hibernate we just turn lazy loading off so that it loads everything. It obviously costs more to do this, but I wasn't sure how to get away from the lazy loading methods that Hibernate would create.

If a Containers has sets of data that are not used often then they will not be loaded and it is up to the requesting UI Form to call it and send it for update. (We built update classes to pass all the information together)

In the case of UI Forms that loaded lots of Containers we just make special classes and fill in what we need for them. They are sort of read-only containers that aren't used for persistence.

There may be better ways.. but I am learning :)

Arthur Thomas
A: 

I'm just trying to find my way with ORMs.

It's an appealing concept. Like you I don't want other tiers in the application to know that the ORM exists.

What I'm looking at currently is using interfaces that I design and using partial classes (a C#/.net thing, without partial classes I guess I'd write a wrapper) to add the implementation of the interface onto the types that are generated by the ORM.

As far as lazy loading / deferred execution goes, that also should be invisible to the application. It's a nice service for the ORM to provide and I'm happy that it does but my application should not need to know or care about it. So if the ORM doesn't hide that from you then again I'd look at a wrapper that took care of this so that the application does not need to know or care.

Hamish Smith