Folks, please give me a sanity check on a few things:
First some background:
We are building an application with what I would describe as a moderately large domain model. There are not many inheritance relationships, but most objects have at least one association with another object - in many cases a one-to-many relationship. The object model is rooted almost entirely on a single object -- Person. Each Person associated with one or more Case objects. Each Case object contains a lot of data collected during a period of time where the Person is is a consumer of our company. This data is represented in terms of both simple properties, as well as collections of related entites (many of which, in turn, have their own associated entities). So the object graph for a Consumer is fairly deep.
Now for the questions:
1. The domain model was designed with a
lot of unidirectional associations, where the parent has a reference to the child, but not a reference from the child to the parent. However, in some cases, the child sometimes has an Integer property representing the database ID of the parent. For example, something like this:
Code:
-------------
| Person | -------------
|-----------| | Address |
| personId | |-----------|
| addresses | -----> | addressId |
| ... | | personId | (Integer)
|-----------| | ... |
| ... | |-----------|
------------- | ... |
-------------
My opinion, though, was twofold:
- Most importantly, if an object has an ID reference to another object, that reference should be replaced with an actual object reference. More like this:
Code:
-------------
| Person | -------------
|-----------| | Address |
| personId | |-----------|
| addresses | -----> | addressId |
| ... | <----- | person | (Person)
|-----------| | ... |
| ... | |-----------|
------------- | ... |
-------------
- Second, I feel that a bidirectional association is preferred in most cases to a unidirectional association unless the relationship doesn't model a real-world situation (a EBook object on an online bookstore would likely not have a reference to its owner, though the owner object (Customer?) might have a collection of owned books).
Am I wrong on these?
2. Because we are using a Session Facade of remote EJBs (SLSBs) to retrieve information for the web tier, we must have all objects initialized (fetched) before they are passed over the RMI layer (since they have to be Serialized). Because of this, our developers have been using eager fetching in the object mappings a great deal. But this has me concerned that getting a Person object would result in a load of ALL the information for that person that's in the database, even if the data we want is right there in the Person object.
My opinion is that for the most part, the object model should be set up for lazy-loading, and data to be sent back to the client should be retrieved using the Query or Criteria APIs, so that only the necessary data will be fetched and can be immediately sent to the remote client.
Yes? No?
Thanks in advance for your help.