RabbitHunter wrote:
That's a good hint. Thank you.
One more question: How can I achieve this is in a dynamic way via Hibernate API? The amount of the subclasses will only be known at runtime. The subclasses will be loaded in a sequence and the last one should be the one to store in the database.
So there can be a "initial" entity class A and maybe some more like B, C and so on.
So we have the inheritance chain C -> B -> A. In each step, the "@entity" annotation(property) of the actual last subclass should be replaced by a "@mappedSuperclass" annotation/property. As the result, the subclass of the last iteration has to be the entity-class, all others of the chain should be marked as "mappedsuperclass".
Everything you do to that effect must happen before you create your SessionFactory. Of course you might start with a SessionFactory, and later create a new one, but you won't be able to mix instances from sessions originating from different SessionFactorys (at least that is my understanding of the docs).
You can manipulate the Configuration Instance you typically create in HibernateUtil in order to create your SessionFactory from it.
I only added Classes and additional configuration files so I am not so sure about changing the Annotation. But I guess you could build your own Classloader which checks some conditions, and replaces Annotations before loading the class.
kind regards
Jens