Hibernate version:
3.2
Hey all
I have an assignment where I have to model a simple database with
pupils. Each pupil must in turn have a 1-n relationship to other
pupils (the friends table). So far I have this model:
**********
* pupils *
**********
* id *
* other fields omitted...
**********
****************
* pupils_friends*
****************
* id *
* friend_id *
* pupil_id *
* type_of_relationship *
****************
Code:
<class name="com.someapp.model.Pupil" table="pupils" >
<id name="id" column="id" type="java.lang.Long">
<generator class="increment"/>
</id>
<bag name="friends" lazy="false">
<key column="user_id" />
<one-to-many class="com.someapp.model.Friend" />
</bag>
</class>
Code:
<class name="com.someapp.model.Friend" table="pupils_friends" >
<id name="id" column="id" type="java.lang.Long">
<generator class="increment"/>
</id>
<many-to-one
name="pupil"
column="pupil_id"
not-null="true"
/>
<many-to-one
name="friend"
column="friend_id"
not-null="true"
/>
</class>
In my Hibernate mapping each Pupil domain object has a list of PupilFriend objects. To retrieve a list of friends for a pupil you thus have to first iterate over each PupilFriend object and then for each such object get the friend - which probably is the result of a awkwardly designed database model.
In my case I'd like to have a List<Pupil> for each Pupil object, is this somehow mappable?
Thanks!