I'm making a manyToMany relation between two objects, in JPA, and I want to add an extra property on the relation. I've been following the example found at: ManyToMay Example
This works fine, but:
1. The relation table in DB will get two id columns for each object, one as primary key and one for the foreign key (=four id columns in total). I only want a total of two id columns + my extra attribute in the relation table/object
2. I have to populate the id-columns manually from my code. I want JPA to handle this
3. I always have to persist the objects to connect before I connect them, in order to get their primary keys.
Is there a better best practice for solving this problem? More like the built in @ManyToMany solution, but with possibility for an extra attribute.