I understand, as this is a relatively common occurrence. For instance, in one of my enterprise applications, I maintain security credentials in the HttpSession. When persisting objects, the security credentials need to be accessed to save auditing information (created_by, modified_by columns). In order to maintain the separation of concerns (HttpSession should really only be accessible from UI layers as it is a UI rendering construct), you will have to pass the id_company from the UI layer (whether Struts' Action, Spring MVC's ModelAndView, or simply JSP's scriptlets) to the layer of the application that is involved with persistence operations. If you use DAO's, for instance, an example method signature would be getPersonnelByStartDate(Date startDate, Long companyId), which could be called from your UI layer. In fact, almost all method signatures in your persistence layers would likely pass the companyId as a parameter, since you are restricting access to information given that data.
Yes, it becomes a bit more of a pain when you introduce more application layers in the architecture (you have to keep passing that parameter through your layers), but the first time you have to refactor, the benefits are clear.
|