When to use DiscriminatorValue annotation in hibernate

后端 未结 4 1023
不知归路
不知归路 2020-12-05 06:29

What and when is the best scenario to use DiscriminatorValue annotation in hibernate?

4条回答
  •  孤城傲影
    2020-12-05 06:50

    Here is the explanation and one example on hibernate table per class hierarchy, consider we have base class named Payment and 2 derived classes like CreditCard, Cheque

    If we save the derived class object like CreditCard or Cheque then automatically Payment class object will also be saved into the database, and in the database all the data will be stored into a single table only, which is base class table for sure.

    But here we must use one extra discriminator column in the database, just to identify which derived class object has been saved in the table along with the base class object, if we are not using this column hibernate will throw the exception

提交回复
热议问题