Hi,
I'm using Hibernate 3.0.x and we have a multi-client capabel DB design, which means that every table in the DB has an additional field "client" that contains the id of the client this record belongs to. Note that there exists an ID column as primary key that is unique over all table entries, i.e. the client is not part of the primary key.
Now I have two challanges with this multi-client awareness: First, I have to filter the data on every data retrieval process and, secondly, I have to write the "client" on every newly created record.
Additional architecture information: The client information is stored in a ThreadLocal variable, i.e. it can be accessed at any time.
The Hibernate Persistence layer lies behind a Data Access Object layer, i.e. all data retrieval is done via DAO methods.
For data retrieval I can think of the following solutions, where the first solution (filter) seems to by my favorite:
- I use a Filter that I set at the session creation time.
- I add the filtering manually to every DAO finder/retrieval method.
- I try to use the interceptor or event system in any way (if possible at all).
For data storage I can think of the following three solutions:
- I use an interceptor for writing the client information in the onSave() method.
- I implement the SaveOrUpdateEventListener of the Hibernate event system for writing the client information.
- As all data objects are created via the DAOs I set the client information within the DAO.
My favorite solution is the Filter for retrieving data and the interceptor or SaveOrUpdateEventListener for writing data.
If you have any experience with multi-client applications or if you can think of any other solution or if you have any other comments on this I would be very interested in reading your forum post...
Best regards,
Joern