Partition a large Hibernate model to manage schema dependencies
We are considering splitting our hibernate tables into packages or domains (invoicing, sales, ..etc), primarily for dependency management issues.
It doesn't break neatly of course, so we aren't sure how to handle relationships that cross domains. It would be nice to have a new entity annotation for this, but meanwhile one idea is to make multiple copies of model in which there is some variation in how relations are annotated to 'snip off the loose ends'. These altered entites would probably need to be made 'read only' in the other models they don't belong to. Also, we would keep using the existing full model for a while as we transition apps to use the smaller ones.
So for example, most tables should exist entirely in one model or another; but if Domain1.Table开发者_运维百科1 relates to Domain2.Table2, then you would make a read-only copy of each in the other's domain. The copy would have it's other relationships in it's domain changed into 'dead ends' (probably by replacing relationship links with an integer fk reference attribute instead).
The point being, we'd like to have some way to manage our maven builds so that when someone changes an attribute on a table, we have declared dependencies on just that domain's model, so we can reduce the number of apps that need to be rebuilt. (we have tight deployment outage windows).
Oh, and all the domains have to use the same java package for compatibility with our legacy EJB persistence tool
So that's the idea. Any suggestions/feedback/comments? Thanks!
You suggest copying the related table's entities into the required domains (not it's domain) and then changing it's own domain dependencies into "dead-ends" a.k.a. Integer FK values which could be potentially used to do lookups if necessary.
My suggestion would be you should do this at the edge of each domain and to not copy anything. So if, Domain1.Table1 relates to Domain2.Table2, it simply has a FK, int fields maybe called table2Id. This would creates the dead-ends at the edge of each domain instead of needing crossover and duplication.
I have to ask though...
Are you sure you have multiple domains?
The root of you problem seems to come from the fact that your data is related, indicating to me that they are part of the same domain. For instance, you speak of sales and invoicing as separate domains but they probably both share customer references. This all feels like it belongs together to me. Some projects'/industries' domains are large and breaking them up for convenience and simplicity usually turns out to be a mistake in the end and often adds unanticipated complexity. For instance, if you need to do a Sale look up which should have a reference to the invoice, but instead now you have to do a separate invoice lookup, it makes your API's clients' usage a little heavyweight.
精彩评论