voglio se è possibile gestire un associazione con una astratto Entity (cioè: un Interface), in un'altra entità. ad esempio:
Ho un class
chiamato Foo
che ha un attributo bar
, che è di tipo Bar
, che è un interface
. Le classi multiple (Bar1
, Bar2
) realizzano Bar
e sono tutte anche persistente.Handling un'associazione con un'interfaccia con ORM in Java
class Foo{
Bar bar; // this will be either Bar1 or Bar2
}
interface Bar{
// some methods
}
class Bar1 implements Bar{
String s; // Bar1 and Bar2 have different represantations ,hence they must be persisted to different tables
}
class Bar2 implements Bar{
int i;
}
Ora come posso gestirlo con un ORM in Java? Ad esempio: in modo che quando richiamo un Foo
, è bar
è un'istanza di una delle realizzazioni di Bar
.
Hibernate supporta le tre fondamentali strategie di mappatura eredità: 1. tabella per gerarchia di classi 2. tabella per ogni sottoclasse 3. tabella per ogni classe concreta – amitmah
riferimento: https://docs.jboss.org /hibernate/orm/3.5/reference/en-US/html/inheritance.html Penso che sia possibile gestire le interfacce allo stesso modo delle classi Abstract in Hibernate. – amitmah