Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hibernate interface mapping without using annotation parameter "targetEntity"

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? enter image description here

like image 869
Pumuckline Avatar asked Mar 07 '13 14:03

Pumuckline


1 Answers

Define your mapping contract in a abstract @MappedSupperclass and then override it with @AssociationOverride in the implementation class.

like image 140
ramdane.i Avatar answered Oct 12 '22 22:10

ramdane.i