views:

57

answers:

5

Hi,

I created a class diagram for a system and now I have to model it into a real system. This means converting it to a database.

Now there is a base class which has just a few attributes, but there are many classes that inherit from it. Now my checklist for converting says I have to create a table for every class.

I don't know how to handle the inheritance, I can see that associations are done with PK and FK's but what about subclasses?

Is there some article which handles that or is there someone who can explain it to me?

Thanks in advance,

A: 

Usually, you design your datamodel (database tables/PK/FK etc.,) in parallel when you design your actual class diagram. After identifying all the cadidate classes and the dependencies on each of the classes, you will probably go on with the design sequence diagram. By this time, your data model should have been finalized.

I cannot understand your situation here, but IMO the process that you follow seems a bad idea to me.

Bragboy
A: 

Drop all that UML nonsense - keep it simple. Its just amounts to duplication for no gain. Does Microsoft or Sun publish UML for dOT NET or Java... FOrgetting the odd sample, the majority of these frameworks dont have any official UML anywhere.

mP
A: 

I have modeled my class diagram and added databases stereotypes on each class, attributes etc...These database stereotypes have created java annotation which then creates the database using a mapping tool. To find out how to create subclass you must look at hibernate, EJB3 annotations and add this specific stereotype in your class diagram.

It works really well with Omondo and using object approach is more powerful than first creating your database and then modeling. Why to duplicate the job ?If you have projects requirements then you need to use UML and live code and model synchronization of database annotations which allows the creation of the real word using mapper based on annotations

+1  A: 

You have three alternatives to translate class hierarchies into relational tables: - Create only a table for the superclass (all attributes and associations of subclasses are moved to the table corresponding to the superclass with the possibility of taking a NULL value) - Create only tables for the subclasses: All attributes and associations of the superclass are repeated in each subclass - Create tables both for the superclass and for each of the subclasses. In this case, the PK of the subclasses is at the same table a FK to the superclass (this ensures that all identifiers in a subclass table correspond to an existing identifier in the superclass table. A join between both tables allows to recover the full information of the element)

The best strategy depends on the problem (for instance, the number of attributes in each class, the number of levels in hierarchy, whether the hierarchy is disjoint or not,...)

If you want to see some examples, you can upload your hierarchy to the UMLtoDB online service http://modeling-languages.com/content/uml2db-full-code-generation-sql-scripts-databases

Jordi Cabot
A: 

Maybe next time will be more useful to you to use a entity relationship model and mapper like, for example: darwin (is payed but is the best) keep using uml, and design only idiots thinks it's a waste of time. You could find more data modeler here: http://case-tools.org/database_modeler.html

regards,

alud