I have currently existing database and hibernate mapping for it. There is a central table and corresponding entity (PersistentObject
). Many of the other tables and entities refer to PersistentObject
via @ManyToOne
or @OneToOne
mapping.
Now I'd like to make current PersistentObject
abstract and introduce two sub classes Sub1Object
and Sub2Object
that inherit from PeristentObject
.
I can't change the table where PersistentObject
is stored, otherwise adding new tables etc is possible. The table contains enough information so that I can use e.g @DiscriminatorColumn
to separate Sub1Object
and Sub2Object
rows if needed.
Is it possible make this change so that my current HQL queries still work without modifications? I have lot of queries like from PersistentObject where foo = ?
and from OtherEntity other where other.persistentObject = ?
. I'd like that those queries start returning concrete subclasses instead of the super class. I don't want to code separate queries for Sub1Object
and Sub2Object
.
Is this at all possible? What inheritance strategy I should use?