I have the following scenario:
The User object and the user's Roles on various projects are persisted in the database. The User object and the Role objects are loaded using hibernate when the user logs into the application. Now, if the admin user logs in and changes the Role of the user on a project, then the change is affected only in the subsequent login of the user since the application uses the user and role objects stored in the http session. Whereas i want the changes to reflect instantly. Since the data is present in the detached objects it does not get synchronized when the data is changed in the database.
The question i have now is whether the role objects should always be fetched from the database instead of caching them in memory as objects?
Secondly, what would be the better design approach to fetch the data in various parts of the applications. I had 2 options in mind:
1. Expose a method in the business layer to get roles of a given user and use it wherever the user roles are required. Since this is an existing application, this option would be change in lot of places. 2. Change the implementation of the getRoles() method in the User class to fetch the role objects associated to the user objects from the database every time instead of caching. This would mean that the User class will need access to the DAO. Would it be odd to access a DAO from a domain object.
|