I am unable to understand the use of @ManyToAny annotation in Hibernate. In which case it should be used? I googled it, but the explanations in a couple of websites just bounced over my head...
Can anyone explain it with a simple example? How's it different from @ManyToMany and @ManyToOne?
The javadoc says:
Defines a ToMany association pointing to different entity types. Matching the according entity type is done through a metadata discriminator column. This kind of mapping should be only marginal.
So instead of having a ManyToMany between Student and Course, you could have a ManyToAny between Student and [Course or Teacher], and the metadata discriminator column would say, for a given row, if it points to a Course or to a Teacher.
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