Why hibernate uses a join table for these classes?
@Entity
public class CompanyImpl {
@OneToMany
private Set<Flight> flights;
@Entity
public class Flight {
I don't want neither a join table nor a bidirectional association:(
In Many-To-One Unidirectional mapping, one table has a foreign key column that references the primary key of associated table.By Unidirectional relationship means only one side navigation is possible (STUDENT to UNIVERSITY in this example).
When a join table is used in mapping a relationship with an embeddable class on the owning side of the relationship, the containing entity rather than the embeddable class is considered the owner of the relationship. If the JoinTable annotation is missing, the default values of the annotation elements apply.
The One-To-Many mapping comes into the category of collection-valued association where an entity is associated with a collection of other entities. Hence, in this type of association the instance of one entity can be mapped with any number of instances of another entity.
A Course can have many Students and a Student can take many courses. This creates a Many to Many relationship. The following example shows a unidirectional Many to Many mapping in Hibernate.
Because that's how it's designed, and what the JPA spec tells it to map such an association. If you want a join column in the Flight table, use
@Entity
public class CompanyImpl {
@OneToMany
@JoinColumn(name = "company_id")
private Set<Flight> flights;
}
This is documented.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With