Hi
The typical table for one T1 to many T2 is to have a foreign key on T2 pointing toward T1. The T1_T2 table is usually not needed.
The JPA structure would then be a One-To-Many, possibly two-way.
There could be some arrangements, to make the structure you describe work. You could change T1_T2:
- add a unique constraint on T2 (so that only one T2 is allowed)
Is that really what you want?
Edited: yes, it is what you want ;-)
I doubt you may find many examples on the net. I have no proved solution, but I would try something along these lines:
In Hibernate annotation reference documentation, see "2.2.5.3.2.3. Unidirectional with join table" to get the idea. It looks like:
@Entity
public class Trainer {
@OneToMany
@JoinTable(
name="TrainedMonkeys",
joinColumns = @JoinColumn( name="trainer_id"),
inverseJoinColumns = @JoinColumn( name="monkey_id")
)
public Set<Monkey> getTrainedMonkeys() {
...
}