Is Hibernate Smart Enough to Handle Concrete Parent Classes?
posted 12 years ago
We have a table-per-subclass mapping strategy.
Client --> CLIENT_TABLE | -- ClientTypeA --> CLIENT_A_TABLE ( joined on CLIENT_ID ) -- ClientTypeB --> CLIENT_B_TABLE ( joined on CLIENT_ID ) -- ClientTypeC --> CLIENT_C_TABLE ( joined on CLIENT_ID )
However, our Client class is NOT abstract because when we first insert the Client into the DB, we do not know which type of client it is. Later on, the user inputs more information which determines which type it is. At this point, we construct a ClientTypeX object from the Client object and want to update it. Not too surprisingly, we get a StaleObjectStateException...the desired behavior is for Hibernate to be smart enough to update the Client table and insert into the joined-subclass table for the given Client type. Can Hibernate be configured to handle this??