Bidirectional relationship in MappedSuperclass
In JPA2.0 specification is written:
Persistent relationships defined by a mapped superclass must be unidirectional.
Why can't be used bidirection开发者_如何学运维al relationship in @MappedSuperclass class? I tried it in Hibernate and it looks that it works, can be there some problem with it?
We're generating our model so we need specified all relations in @MappedSuperclass class and extend this class with @Entity class which contains just handwritten code.
I'd guess that it is down to the fact that the mapped superclass cannot have its own table and so is persisted into the table(s) of subclasses, and if there are multiple subclasses of the mapped superclass then the relation back from the other side doesn't have a single FK to follow to get to the mapped superclass information. In that way, most JPA implementations will allow it but typically when there is a single subclass of the mapped superclass.
Obviously you'd have to ask the JPA EG for their reasons since they don't bother mentioning them in their spec.
精彩评论