Skip to main content

JPA : Inheritance with join and ManyToOne

1 reply [Last post]
yagt
Offline
Joined: 2010-07-24

Well, I'm working In a project where it's defined the following relation in the database . I have dates that can be of different types . We can find TypeA date and TypeB date . This case, with JPA // Hibernate I have represented via InheritanceType.JOINED to create three tables . The father table ( DATE ) , and the DATE_TYPE_A table, and the DATE_TYPE_B table.

on the other side, either DATE_TYPE_A instances or DATE_TYPE_B instances can take place in diferent places, so DATE_TYPE_A has a relation of manyToOne with PLACE A and DATE_TYPE_B has a relation with PLACE B of manyToOne.

ok, once the problem has been presented, I can't mix everything . The place A looks for the identifier of DATE_TYPE_A :

...

@OneToMany(mappedBy="citaId")
private List listaCitas;

...

and in DATE_TYPE A :

...

@ManyToOne
@JoinColumn(name="centroSalud",referencedColumnName="nombre")
private CentroSaludEntity centroSalud;

...

The problem appears when PLACE_A looks for citaId, As I have defined this kind of inheritance, citaId is present in the father table, not in sons, so it cant be found . I can use a SINGLE_TABLE_INHERITANCE, of course, but I want to know if there's a way to reference the father identifier.

Thanks

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
yagt
Offline
Joined: 2010-07-24

Ok, it's solved . I have to reference to the foreign key, instead of the primary key 'IdCita' . Thanks anyway