I have the following mapping. It works fine. the problem is that Hibernate created 3 tables for that: request
, research
and request_researches
.
request_researches
is not needed.
I want the foreign key to be inside the research
table. (research.request_id
)
@Entity
public class Request{
@Id
private Long id;
@OneToMany(targetEntity = Research.class,cascade= CascadeType.ALL, fetch = FetchType.EAGER)
private List<ResearchEntity> researches = new ArrayList<>();
//... getters setters
}
Is this possible?
Thanks
Just add a @JoinColumn
annotation where you specify the column from the related entity:
@OneToMany(targetEntity = Research.class,cascade= CascadeType.ALL, fetch = FetchType.EAGER)
@JoinColumn(name = "request_id")
private List<ResearchEntity> researches = new ArrayList<>();