Nickname11
Nickname11

Reputation: 571

Spring JPA Hibernate - how to access many-to-many table and join-table?

I would like to have access to related Many-to-many table, as well as to the join table.

That's how this is going to look in database:

enter image description here

So, let's say I would like to have access from "X" to "Y" and "Z".

Is it ok, to simply add "Z" with @ManyToMany, and "Y" with @OneToMany annotation?

Right now it is purely theoretical question, I'm just designing this app, and this looks kinda strange, so I would like to know if it is common and correct way to to that.

Upvotes: 0

Views: 253

Answers (1)

Krisz
Krisz

Reputation: 2224

If you want to model your join table you can use ManyToOne on the join table when referring to X or Z and OneToMany on the side of X and Z. You would use ManyToMany when you don't want to model the join table.

Upvotes: 1

Related Questions