In a simplified situation like this one, with 3 classes:
class ClassONE{
protected List<IntermediatedClass>;
(... getters / setters)
}
class ClassTWO
protected String someData;
(... getters / setters / iniciate List etc...)
}
class IntermediatedClass{
public ClassONE one; //Points to an object (row) of ClassONE
public ClassTWO two; //Points to an object (row) of classTWO.
public Double data; //Data that need being saved with this particular relation between obj1 and obj2.
}
I know that with Hibernate you can declare a ManyToMany monodirectional relationship between class1 and class2. Class1 can have some objects of class2, and class2 can be on some objects of class1. Thats just [CLASS1] N —- N [CLASS2].
I want declare a [CLASS1]1—N[INTERMEDIATECLASS]N—1[CLASS2] typical N-N database implementation. Intermediate class has an attribute very important: data, a Double type. I cannot find the way to declare IntermediateClass as my own way to implement this N–N with this data in Hibernate Annotations.
Any help, please? Just with this simple example i can solve my trouble. I didnt would make my tries on it in order to maintain clean the code for your understanding.
You can create a full blown bidirectional many-to-many mapping with an intermediate mapping class with additional properties the same way you would design your ER model:
And the mapping class:
But since bidirectional associations like this can get rather messy and hard to maintain in your application code I would do without the bidirectional association and just define the two unidirectional many-to-one associations in class AB.