It seems that if you make lazy choices, like you do with getSeat, you will only get the parent, not the subclass. I tried the same example with FetchType.EAGER and getSeat correctly returns LeatherSeat.
I'm not sure why sleep mode can get a car with LeatherSeat when for EAGER fetch, but sleep mode can not get it when it does a LAZY fetch. Something seems to be broken there.
There is a ticket about discriminator columns in InheritanceType.JOINED where a dot is made regarding this scenario. https://hibernate.onjira.com/browse/ANN-140 , but the ticket was rejected, indicating that sleep mode was too elegant to require a discriminator for InheritanceType.JOINED. However, it cannot correctly return subclasses to lazy samples.
Then this ticket https://hibernate.onjira.com/browse/HHH-271?focusedCommentId=44089#comment-44089 is more specific for this problem, and the answer was “how do we expect to know which subclass to get lazy choice?
Both tickets are old and were rejected. It seems to be a problem for me. But for now, you’ll have to switch to a different type of inheritance or use the desired type of fetch, since this matches the design of the sleep mode.
source share