I am recently trying to introduce interfaces for some of my hibernate mapped entities and can not figure out how to configure the mapping.
When I used the Interface without any further declarations, I always got the following Exception:
org.hibernate.MappingException: Could not determine type for: ...MyInterface
Then I found out that everything works fine, when I define the targetEntity explicitly:
@OneToOne(targetEntity=InterfaceImpl.class)
private MyInterface myInterface;
Unfortunately, this solution does not work in my case: I can not define the targetEntity through annotation as I want to extract this class to an common external library that will not contain and even not know the final implementation of the interface.
So is there an alternative way for declaring which implementation should be used, that I could use outside the extracted library?
Define your mapping contract in a abstract @MappedSupperclass
and then override it with @AssociationOverride
in the implementation class.
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