@OneToOne to Interface


I have a solution to deal with this case but I’m not sure it’s correct or there is an easier solution.
I am using the @Any annotation …
Is that correct in your opinion?

Otherwise I could declare the interface as an @Entity but I don’t know all the classes that implement the interface

public class Contact extends PersonnePhysique {
  @Any(metaDef = "ACTEUR", metaColumn = @Column(name = "OBJETMAITRE_ROLE"))
  @JoinColumn(name = "OBJETMAITRE_ID", columnDefinition = "varchar2(25 char)")
  private IPossedeContacts objetMaitre;

public interface IPossedeContacts

What do you mean you don’t know the classes? AFAIK you have to specify all classes in the @AnyMetaDef(metaValues), so you have to know the classes. You could also use the table per class inheritance strategy for which you really don’t need to specify all possible tables/entities, but the final SQL query for the data will then use a big union over all possible tables. Not sure if that is acceptable for you. Anyway, I have no idea what your exact requirement is, so anything could be correct. The mapping looks ok to me though.

Ah if sorry, I did not put everything, I know the list of classes, see below.

But I was wondering what the most common practice is for an interface.
Ok for the interface, it works with @Any.

But for inheritance, we should not use the interface, right?

  name = "ACTEUR",
  idType = "string",
  metaType = "string",
  metaValues = {
    @MetaValue(value = "com.hermes.ref.acteur.businessobject.Acteur", targetEntity = Acteur.class),
    @MetaValue(value = "com.hermes.ref.acteur.businessobject.ActeurGenerique", targetEntity = ActeurGenerique.class),
    @MetaValue(value = "com.hermes.ref.acteur.businessobject.ActeurInterne", targetEntity = ActeurInterne.class),
    @MetaValue(value = "com.hermes.ref.acteur.businessobject.AgenceBancaire", targetEntity = AgenceBancaire.class),
    @MetaValue(value = "com.hermes.ref.acteur.businessobject.Agent", targetEntity = Agent.class),
    @MetaValue(value = "com.hermes.ref.acteur.businessobject.Collectivite", targetEntity = Collectivite.class),
    @MetaValue(value = "com.hermes.ref.acteur.businessobject.Commune", targetEntity = Commune.class),
    @MetaValue(value = "com.hermes.ref.acteur.businessobject.Contact", targetEntity = Contact.class),
    @MetaValue(value = "com.hermes.ref.acteur.businessobject.EntiteAdministrative", targetEntity = EntiteAdministrative.class),
    @MetaValue(value = "com.hermes.ref.acteur.businessobject.Fournisseur", targetEntity = Fournisseur.class),
    @MetaValue(value = "com.hermes.ref.acteur.businessobject.GestionnaireConcession", targetEntity = GestionnaireConcession.class),
    @MetaValue(value = "com.hermes.ref.acteur.businessobject.Intercommunalite", targetEntity = Intercommunalite.class),
    @MetaValue(value = "com.hermes.ref.acteur.businessobject.Partenaire", targetEntity = Partenaire.class),
    @MetaValue(value = "com.hermes.ref.acteur.businessobject.PersonneMorale", targetEntity = PersonneMorale.class),
    @MetaValue(value = "com.hermes.ref.acteur.businessobject.PersonneMoraleAbstraite", targetEntity = PersonneMoraleAbstraite.class),
    @MetaValue(value = "com.hermes.ref.acteur.businessobject.PersonnePhysique", targetEntity = PersonnePhysique.class),
    @MetaValue(value = "com.hermes.ref.acteur.businessobject.SignataireDestinataire", targetEntity = SignataireDestinataire.class)

I have defined the targetEntity with the parent class “Acteur.class” which contains all the classes that implement the IPossedeContacts interface. It works.

So I was able to remove the @Any to use the @ManyToOne.

  @ManyToOne(targetEntity = Acteur.class)
  @JoinColumn(table = "TPERSONNEPHYSIQUE", name = "OBJETMAITRE_ID")
  private IPossedeContacts objetMaitre;