Hi
I'm trying to define a OneToMany / ManyToOne relationship.
I have the following JPA:
class Definition {
@OneToMany(cascade = CascadeType.ALL, targetEntity = LexicalForm.class, mappedBy = "strongNumber")
@JoinColumn(name = "raw_strong_number")
private List<LexicalForm> lexicalForms;
@Column(unique = true)
private String strongNumber;
}
And
class LexicalForm {
@ManyToOne
@JoinColumn(name = "raw_strong_number", referencedColumnName = "strong_number")
private Definition strongNumber;
private String rawStrongNumber;
}
When I run a query, it produces the wrong join, using the id from Definition and joining it to strongNumber from Lexical form.
select distinct
t0.id c0, t0.accented_unicode c1, t0.step_transliteration c2, t0.step_gloss c3
from definition t0
join lexical_form u1 on u1.raw_strong_number =
t0.id where (u1.raw_form like ? or u1.unaccented_form like ? )
If I add the strong_number to my Definition class in the join column: @JoinColumn(name = "raw_strong_number", referencedColumn = "strongNumber"), I get loads of errors spurned out:
Error with the Join on [com.tyndalehouse.step.core.data.entities.lexicon.Definition.lexicalForms]. Could not find the matching foreign key for [id] in table[lexical_form]? Perhaps using a @JoinColumn with the name/referencedColumnName attributes swapped?
Same thing occurs if I swap round the referencedColumn and name columns.
Any ideas? Is this case supported?
Cheers
Chris