Inbetween i found out that i can use multiple @Ids in one Entity and reference them.
This way lazy loading does work, but it offers us another problem.
In our tables we have the composition of two fields: 'id' and 'endstempel_id'. They are our primary key now.
We use these columns for history saving, and the latest entry is always the one with id:x and endstempel_id: 3999999999.
What i have to do, to make lazy loading work, is to add a foreign key column for every other table i reference too.
For my example this means i have to add a adresse_endstempel_id column in the unternehmen table, which defaults to (and always is): 3999999999.
This seems stupid to me, but this is the only thing i found so far.
And what seems worse is that, for every relation i have in my table (another adress, user, etc.) i have to add another foreign key column, which always has the entry 3999999999, which just causes my DB to get filled up with useless data.
This is the code i have now:
Code:
@OneToOne(targetEntity=net.zmuek.backend.domainmodel.adresse.Adresse.class, fetch=FetchType.LAZY)
@JoinColumns ({
@JoinColumn(name="unternehmen_hauptadresse_id", referencedColumnName="adresse_id"),
@JoinColumn(name="unternehmen_hauptadresse_endstempel_id", referencedColumnName="adresse_endstempel_id")
})
and
Code:
@Id
@Column(name="adresse_endstempel_id")
private Long adresse_endstempel_id;
@Id
@Column(name="adresse_id")
private Long adresse_id;
Is there a way to work around this? What i imagine is to tell hibernate that the
Code:
@JoinColumn(name="unternehmen_hauptadresse_endstempel_id", referencedColumnName="adresse_endstempel_id")
is our fixed 3999999999 value.
Greetings
Sven