Here's my application : the purpose is to add records based on errors (but not all errors will result in adding a new record, only the Main Errors). Every session has many errors, then an internal service will manage this errors to know which are the Main Errors (and which are the 'small' errors, I mean the implied or related or attached to this Main Error).
UML Diagram :
So I need your help and suggestions about my UML Diagram, do you think that is the best approach? do I really need the subclassing here (or maybe just putting two different classes Error and MainError would be better) ?
Thank you very much
I think the following diagram would satisfy and restate your requirements clearly.
What this expresses is:
Session
encounters zero or more Errors
Error
is encountered in one Session
Error
must be an instance of one and only one of its subclasses ("complete" means an instance must be an instance of a subclass; "disjoint" means an instance cannot be multiply classified, which is impossible in Java anyway.)Main Error
causes zero or more Subordinate Errors
Subordinate Error
is caused by zero or more Main Errors
What is implied is that every Error
is initially created as an Unclassified Error
and later classified into either a Main Error
or a Subordinate Error
.
I didn't bother to model Record
, as it is far too nebulous and adds nothing to the discussion.
If you were to implement this model, the association ends would undergo a name change that retains semantics while becoming normalLookingCamelCaseForJava. Here are the name changes:
encounters
would become encounteredErrors
and be of type List<Error>
encountered in
would become encounteringSession
of type Session
causes
would become causedSubordinateErrors
of type List<SubordinateError>
caused by
would become causingMainErrors
of type List<MainError>
In JPA you could map all the error classes to one table with a discriminator, which will make the reclassification much more performant. (See changing entity type in JPA for an idea of how you might do so.) Note that you might want to map many-to-many associations to separate relational database tables. That's a separate discussion, though.