That depends - do you want the association to be unidirectional or bidirectional?
The most basic approach, if a Student has many Subjects, would be to define a many-to-one association in the Subject mapping to Student. Thats unidirectional. If you wanted to make it bidirectional you would also add some sort of appropriate Collection mapping in Student, which has a one-to-many association with Subject.
Make sense? [ April 22, 2005: Message edited by: Paul Sturrock ]
Its not in the spirit of this site to do people's work for them, so I won't post you an example. But I will try to explain again what you could do.
The way you have defined your two objects Subject looks like a dependent object - i.e. one doesn't exist without a Student (unless student_id is nullable). So your Student might have a property called 'subjects' which could be a Set. You would add a <set /> element to the Student.hbm.xml file with a one-to-many mapping to your associated class (and this is explained in the documentation). Your Subject class would have a property called 'student' which would be of the type Student. In the Subject.hbm.xml mapping file you would have the other side of the association, which you define as a many-to-one association the Student class. Again how to do that is in the documentation.
Try it. Feel free to post any problems you have/exceptions you encounter.
Don't do this. If you need a relation just implement one more query in the data access layer. Usage of this complex DTO that have dependencies has big disadvantages: 1. Automatic DTO regeneration is difficult and sometime is not possible. 2. If you latter decide to jump from H to something else then you should rewrite you DTO because another framework probably do not support relation mapping. 3. If you load related objects together with a main one then you slowdown the load cycle. If you use lazy load than sometime collision between different collections could happen. I have got such cases and completely get rid of all relations in my DTO. Using of queries require a little more work but much safe.
Good luck for yourself.
That new kid is a freak. Show him this tiny ad:
a bit of art, as a gift, the permaculture playing cards