hiber123 wrote:
Many thanks tchize!!
Sorry to be so naive. I am very new to hibernate. What is the basic difference between 'one to many' and 'many to one' association in hibernate?
the type of association rules how hibernate will manage update / insert in database.
one to many and many to one is just a matter of the side you look the association from. (at SQL level there is no difference as SQL queries allows you to explore association both ways). However at objects level, you can only explore an association in a given direction only if there are appropriate getters. If you want to explore a given association both way, you have to put appropriate getters on both classes. Hibernate requires you to create a descriptor for each class. This mean you have to describe the association, in the good direction, for each descriptor. But you seem to have already understood it considering your suggested code.
Quote:
Can I map my classes like i have defined below?
Class for table 1
has a one to many association on table2 (part_id -> part_id)
has a one to many association on table 2(part_id -> replacing_part_id)
a) inverse atttibute is set to "true" for both these mappings.
b) Class has two HashSet instance variables.
class for table 2
has Part as the instance variable.
Is this correct? Please let me know.
i'll say, table 2 has two parts and not one (one part representing the part_id field and another part representing the replacing_part_id field :)
i suppose you plan to have the one to many association represented by a <set ...> tag in .hbm overall it seems to correspond to you request :)