I inherited a DB Schema that stores product information on a per seller basis. The problem is, each seller gets their own product table. Each product table is identical in schema, but a new table is generated each time a new seller is added to the application, resulting in tables like:
Product111111
Product222222
Product333333
Product..........
Where 111111, 222222, are Seller IDs.
Aside from the atrocious DB design which I must conform to my question is this:
Is there anyway at runtime to query this type of schema? Options I have considered:
When I initially create the SessionFactory, dynamically add mappings for all Product..... tables. The only problem here is detecting when a new Seller is created and re-generating the SessionFactory.
Creating a SessionFactory per Seller??? When I need to query Products for a given Seller create a fresh SessionFactory or retrieve a cached SessionFactory with only the Product.... mapping.
Are they any Hibernate tricks/advanced uses that could help me with this situation?
|