Explicitly create Class for joining table or not for Java JPA many-to-many relationships
For those who have used Java JPA (Hibernate or EclipseLink) I wanted to ask your opinion on the best way to represent m2m relationships in the Entity classes. The choice as I see it is to create 3 Entity Classes, with the intermediary table having two many-to-one relationships, or use 2 Entity Classes, each maintaining a bi-directional Many-to-Many. Here is a discussion I found that sums up my question https://stackoverflow.com/questions/2881160/2-one-to-many-instead-of-1-many-to-many
I can see the benefit of both ways, but I wa leaning toward have the three tables. For example, imagine an Invoice and Product table with a m2m between them. It makes sense to me to create an "Invoice Line Item" table that maintains a m2o to both Invoice and Product, effectively creating the m2m between Invoice and Product. However, I do know not all m2m have a joining table that makes logical sense for exposure. But the answer in the link above seems to indicate that keeping the DB clean of orphan records suggests still creating the JPA class for the intermediary table, even if it's practically a hidden element to users.