OrBee (52) [Avatar] Offline
I have been looking at ways to best model an object in Hibernate which naturally has lots of relationships without making the objects too heavyweight but that seems to be difficult to accomplish. Here is a scenario I have come across a number of times.

Customer entity has some of the following:
Has Sales Agent
Has multiple addresses
Has mutliple Bank accounts
Has mutliple Insurance Policies
Has multiple cars
Has multiple Insurance Coverages
Has multiple DrivingHistory;
Has multiple Claims
Is associated with multiple drivers on the policy
... the list goes on for the customer relationships

Is the only way to model the customer to have all the relationships contained within it as lists of objects? For example

public Customer{
List<Address> addresses;
List<Policy> policies;
List<Vehicle> vehicles;
List<Coverage> coverages;
List<DrivingHistory> drivingHistories;
List<Violations> violations;
List<Claims> claims;
SalesAgent agent;

One problem I have seen with this approach is that the CustomerDAO becomes a God class. Is there any other way to model this differently?
demura (1) [Avatar] Offline
Re: Looking for ideas in book for modeling customer entity
Hi OrBee,
I think a better approach is detailed in the book at section 6.3. (and see the advices at the end of 6.3.1 too). Instead of the several @OneToMany associations (addresses, policies, vehicles, etc.) you could use unidirectional @ManyToOne associations on the other side (Address, Policy, Vehicle). I've found that most times if I need a list of these associated entities (like drivingHistories), I always have to add other criteria for retrieving them : paging, sorting, filtering conditions. So it's easier to maintain these associations on the Many side, and using (named)queries for listing them, in another DAO.