简体   繁体   中英

JPA Inheritance IdClass Location best practice

Where to define @IdClass annotation in both Scenario ?


In my view for case 1 : both Entity1 and Entity2 should have their own @IdClass .

because Entity2 also have primary key .


and for case 2 : MapedSuperClass2 should have @IdClass .

because both Entity1 & Entity2 shared the same primary key .


Is i am right ?

Case 1:

在此输入图像描述

Case 2:

在此输入图像描述

In the first scenario, when you define the IdClass in the parent class you can not add or even delete fields of the key in the subclasses, so adding new value to the key in Entity2 is not allowed by the specification.

In the second scenario, consider create the @IdClass in the second MapperSuperClass to be used in all the subclasses, as you dont need more fiels added to the key, that should work.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM