I need to mapping to a interface (since it has more than one implementation), but because JPA 1.0 spec doesn't support this, so I try to find solution using Hibernate Annotation, I googled some related topics and didn't find some useful information(some of them are too old, eg 2006,2007...)。 One solution I found was add "targetEntityClass" to @OneToOne and so on, but because my interface has many implementation its not a good answer. My code is like this:
Code:
public interface Foo{
...
}
public class FooA implements Foo{ ...}
public class FooB implements Foo{ ...}v
public class Bar {
Foo foo;
}
Bar is an entity, how could I resolve the mapping using Hibernata Annotation?
Maybe i can introduce one AbstractFoo class, and use it as the "targetEntity" for foo.
Code:
public class Bar{
@OneToOne(targetEntity = AbstractFoo.class)
Foo foo;
}
public abstract class AbstractFoo implements Foo{ ... }
public class FooA extends AbstractFoo{ ... }
public class FooB extends AbstractFoo{ ... }
but I don't like this very much since it mix my design and implementation together. Does any one know any good solution?? Thanks.