I'm going to store messages from external products in a database. All messages are the same and have a CATEGORY property. Since most queries that will be done on the db filter the category my DB Architect suggested to split the one table into one table per category.
Normally I would need one Class per table. Unfortunately There are more than 100 Categories...
Is it possible to implement my scenario with JPA/Hi开发者_如何转开发bernate?
I don't think there is an easy way to do that, other than generating the 100 subclasses. If every category of messages has the same properties, the subclasses should be very simple, and could be automatically generated by a small program). This, however, will only work if the set of categories is static, and not dynamic.
However, I would first challenge the design of the architect. By doing this, you will lose the ability to
- have foreign keys to messages (since they will be distributed in 100 tables)
- have unique constraints across messages (even for their ID)
- have sane queries over different message categories
And I don't think you'll gain much, because if the indexes over the table of messages include the category column, the query should be as fast as if the messages of a category were in a dedicated table.
精彩评论