I have a class TimeTable that contains a set of objects of type Year.
A Year does not have any referene to any TimeTable.
On my database the relation is the other way ’round:
In the YEARS table is a foreign key TIME_TABLE_ID.
I’d now like to add my persistence annotations to those classes, but I can’t find out the exact syntax for pure JPA (only for Hibernate which I don’t want to use at the moment).
I think it could be sth like this:
class TimeTable{
....
@OneToMany
@JoinTable(name = "YEARS",
joinColumns = @JoinColumn(name = "TIME_TABLE_ID"),
inverseJoinColumns = @JoinColumn(name ="ID" ???)) // #### here ####
private Set<Year> years;
...
}
.. but I can’t find out what this inverseJoinColumn is 🙁
Is it the name of the ID of an entry in the TIMETABLE table?
The inverse join column is optional, I would recommend removing it, since your setting up a one to many relationship and it is not needed. The
@JoinTableannotation is primarily used for mapping many to many relationships, a scenario you do not need to account for. Instead of@JoinTableuse@JoinColumnto map this one to many relationship.http://www.objectdb.com/api/java/jpa/JoinColumn