I have the following problem:
We want to change our object to relational mapping tool to hibernate.
In our previous mapping tool we used the following strategy:
- table-per-concrete-class
- identity id generation
- generate POJO's from our mapping-document.
We don't need polymorphism !!
If I do this with hibernate I can choose the following solutions:
1. union-subclass mapping.
This seems to me the best solution for table-per-conrete-class, but then we have to change the id-generation method. Now we generate an Id which is unique for each table. But when we have to use union-subclass then we have to convert our id-generation strategy to a global generation strategy.
If we do that then we have a big backwards compatabiliy problem, because I have to change the ids of the records to global ids. And I have to change the foreign keys with them.
So this solution is very difficult to apply.
2. define multiple classes.
Then I will use the simple way of mapping
Code:
<class name="SubClass1" extends "SuperClass>
..
</class>
<class name="SubClass2" extends "SuperClass>
..
</class>
Now I have to write SuperClass by hand. I cannot generate it. And also have to define the common properties twice ( One time in SubClass1 and one time in SubClass2 ). This will generate in the code my properties twice.
I can relax this drawback when I use
<!ENTITY allproperties SYSTEM "SuperClass.xml">
This solution is possible, but has some drawbacks:
- I have to write the SuperClass by myself
- I have to use ENTITY to prevent double coded xml ( I don't like this )
- From ideal perspective the common properties have to be defined in the super-class.
Discussion
Is it possible to relax the usage of union-subclass, so that I can use identity id generation ?
Of course I will accept the drawback that I break polymorphism.
Or maybe the SuperClass of solution 2 have to be generated with the properties shared in the SubClasses.
Or I have to accept this situation.
What do you think ?