Do people use it this way often? I know I've come across a couple situations where this would be handy - unless my thinking is skewed (which is very likely ;) ).
I know it can be done in jdbc - but I thought a hibernate abstraction of this function could be helpfull in ensuring value constraints were still met (i.e. a not-null constraint on the name property of the subclass). Also, in situations where this is performed often, constant cache invalidation would cause a performance hit.
My view of how this would actually work would be something like this:
Code:
Entity entity = session.load(Entity.class, integerValue);
NamedEntity namedEntity = session.promoteToSubclass(NamedEntity.class, entity);
namedEntity.setName("Entity Name");
session.update(namedEntity);
The
promoteToSubclass function would return a special proxy object that would cause the persister to create the sql described above, also the cache invalidation would be handled either at that point or when
update was called (whichever is appropriate).
Thoughts?