There is a way to use a interface as OneToMany relationship using Hibernate? I mean I have a class Document and it has a column List to me to get all records. For each MyInterface I need to have a different concrete class.
1 Answers
I think the question is:
Why you want to use Interfaces and not abstract classes, in a object hierarchy use of abstract classes that can be mapped as @MappedSuperclass makes more sense than use Interfaces, as the interfaces does not play in the model hierarchy that is persistent, just define new implementation but that implementation, I mean the method override are not saved in the database.
So you could use an entity that extends from your parent class and implements the interfaces.
Just keep in mind that entity hierarchy that is saved in the database will depends on parent child relationships not in different implementation of their method as you save the state of the object.
The you could use something like
@OneToMany
Set<MyParentClassThatImplementsMyInterface> object;
So parent class will be.
@MappedSuperclass
public abstract class MyParentClassThatImplementsMyInterface implements MyInterface{}
@Entity
public class MyImpl1 extends from MyParentClassThatImplementsMyInterface
Remember queries are polyphormic

- 18,778
- 7
- 63
- 86