I have article
table and several user tables a_user
, b_user
, ... with exactly the same structure (but different data). I can't change anything in *_user
tables except their table name prefix but can change everything else (user tables contain only user information, there is nothing about article or user_type in them).
I need to link article to a user (many-to-one), but user table name is defined by user_type field. For example
Article table record:
...
user_id="5"
user_type="a"
means that it is linked to a user with id=5 from a_user
table (id 5 is not unique in users scope, each user table can have its id 5).
Any suggestions how to handle this situation? How can I map this relation in Hibernate (xml mapping, no annotations) so it will automatically pick up correct user for an article during select/update? How should I map user tables (one or multiple classes?)?
I would need to run some queries like this:
from Article a where a.userType=:type and a.user.name=:name
Thanks.