0

For example, i have 3 tables:

Man: int pk_id

Junction: int fk_m_id, int fk_w_id, String some_info Object Man, Object Woman

Woman: int pk_id

The junction table has Man and Woman's foreign keys as attributes, but it also has Man and Woman objects inside it and also some extra information, so there is no need for m_id and w_id foreign key attributes, because the id's are already inside the objects. How can i remove the id attributes and only have the objects inside it and make hibernate aware that the foreign keys are inside the objects? The junction table also exists in db and has some extra attributes (String some_info), so can't do it with many-to-many..or can I?

Hope this makes sense.

  • You seem to have a simple ManyToMany association. Read http://docs.jboss.org/hibernate/core/3.6/reference/en-US/html_single/#collections-bidirectional. The Junction entity isn't necessary. – JB Nizet Jun 28 '12 at 09:30
  • Sorry, I forgot to mention. The database that needs to be updated is actually the junction table and there are some extra attributes in it. –  Jun 28 '12 at 09:42
  • Then you have two OneToMany associations: one betweenMan and Junction, and one between Woman and Junction. The same documentation explains how to map them. – JB Nizet Jun 28 '12 at 10:06

0 Answers0