Minion
Minion

Reputation: 125

Hibernate one to many and many to one relationship concept

I am trying to learn Hibernate and just got a bit confused.

I have 2 classes Company and Employee. Company has a set of Employee.

So inside Company i have defined something like

@OneToMany(cascade = CascadeType.ALL)
@JoinColumn(name = "COMPANY_ID")
private Set<Employee> employees;
  1. Now do i need to define something like

    @ManyToOne(cascade = CascadeType.ALL) @JoinColumn(name = "COMPANY_ID") private Company company;

inside Employee class as well and also how will it make the difference.

  1. What will be the difference if i don't define ManyToOne mapping ?

Upvotes: 0

Views: 118

Answers (1)

Michael Wiles
Michael Wiles

Reputation: 21186

See https://howtoprogramwithjava.com/hibernate-manytoone-unidirectional-tutorial/

It all depends on whether you want a uni-directional one to many or a bi-directional one to many

Upvotes: 0

Related Questions