I have read several examples about creating associations between tables with Hibernate and I have got a little bit confused. I want initilaly to know how many tables will be created in the database without specifying any annotation on the other side as with the code:
@Entity
public class Flight implements Serializable {
@ManyToOne( cascade = {CascadeType.PERSIST, CascadeType.MERGE} )
@JoinColumn(name="COMP_ID")
public Company getCompany() {
return company;
}
...
}
I suspect two tables Flight, Company and the Flight contains a foreign key Company_Id. AM I right? What is the difference if I add the "mappedBy" on the other side as:
@Entity
public class Company {
@OneToMany(mappedBy="company")
public Set<Flight> getFlights() {
...
}
}
How many tables will be created by the second approach? I suppose the second approach establishes a bidirectional association. What is practical difference between the two cases? What is going on also with the "mappedBy" annotation in the @ManyToMany association?