Working on a JPA 2.0 compliancy kit for my internship. Part of that kit is to cover corner cases.
@MappedSuperclass doesn't have an original table since it's not an entity.
JSR-317 states this interesting bit:
A class designated with the MappedSuperclass annotation can be mapped in the same way as an entity except that the mappings will apply only to its subclasses since no table exists for the mapped superclass itself.
"Since no table exists for the mapped superclass itself."
Does this mean "no default" - you can make your own table if you want to but it won't be retrievable on its own?
Or does this mean "no table can exist for the mapped superclass" - you're not allowed to create one (with @SecondaryTable)?
According to JPA 2.0, is it allowed to map part of a @MappedSuperclass to a @SecondaryTable?
I am not sure do you mean having @SecondaryTable-annotation in mapped super class or having attributes defined in mapped superclass persisted to the table that is @SecondaryTable in entity that derives mappings, so I try to answer to both.
Mapped superclass does not have table of it's own. Context were mapped superclass is used defines table. This makes sense, because otherwise inheriting mappings to the multiple entities from one mapped superclass would always produce need to override name of table in all other except one deriving entity.I think "no table exists for the mapped superclass" closes also use of @SecondaryTable out.
Also XML Schema given chapter 12.3 of JPA 2.0 specification does not allow secondary-table for mapped super class.
But using column-element of @AttributeOverride in entity to have attributes derived from mapped superclass to be persisted to the secondary table of entity should be fine. There is nothing in specification that talks against such a case.
So I think that "no table can exist for the mapped superclass" is true, but nothing keeps you from placing those attributes to the secondary table of entity. Decision about table for column takes place in entity that derives attribute and association mappings, not in mapped superclass itself.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With