I am new to Hibernate so my question could be seen as a very straight forward one, also I will try not to be too generic (as I am always told off because of that), although as with all architectural question it is hard to avoid that... I never know where to ask these questions.
I have setup a webapp using Spring + Hibernate. My architecture uses a series of Controllers which make use of Services that ultimately call DAO methods to obtain my domain objects.
I also have a GenericDAO which implements all the basic data access methods (findAll, findById, save, delete, update...) which I extend for my concrete Dao so I only have to implement specific data access methods.
So a request to view all users will have this flow: the proper controller is called through request mapping, which feeds the view with the result from calling
userService.getAllUsers() which at the same time makes a call to
This is all nice and I think I'm doing it properly enough.
My question relates to relationships among domain objects, so let's say users have accounts and for one view I want to show the user's details plus his list of accounts.
I never found out what's the best way to gather the accounts object list. Should I mark the relationship as Eager? Should I make a call like this:
user.accountList = accountService.findAccountsByUser(userId);
if that's the case then what's the point of specifying the relationship in the first place? Or maybe I am missing some other way here?
What happens with Many to Many relationships? Am I forced to create a domain object called UserAccount (assuming an account can be associated to several users) that maps the relations between the two?