views:

37

answers:

1

Say i have a cms with only one object called Article (for the sake of this example) with an ID and a title. This CMS implementation becomes part of a framework and is used as a library: e.g. CMSFactory.CMS.SaveArticle(a);

The problem is that depending on the project requirements an article object may have more fields such as SomeDate. Is there any way to declare this relationship and still save an article with all its extra (project-dependent) fields without changing the base CMS library (but able to declare new mappings or so)?

A: 

You could create a subclass of Article with the specific fields for the project:

class SpecialArticleForThisProject: Article {
  public DateTime SomeDate {get;set;}
}

And map SpecialArticleForThisProject using one of the three inheritance mapping strategies.

The base CMS library wouldn't require any changes.

Mauricio Scheffer
This was my original approach but was quickly reverted. From these inheritance mapping strategies only 'Table per concrete class' allows you to maintain the original mapping/object intact. the problem there is that you have to re-write your mapping file inclkuding all the properties from the original mapping. the table will also not represent the extension object but all the properties - so the schema changes as well. Am i totally off the mark here?
Yannis
The docs say: "It is possible to define subclass, union-subclass, and joined-subclass mappings in separate mapping documents, directly beneath hibernate-mapping. This allows you to extend a class hierachy just by adding a new mapping file. You must specify an extends attribute in the subclass mapping, naming a previously mapped superclass."So you don't have to change your original mapping.
Mauricio Scheffer