View Full Version : hbm example for foreign key usage ?
Hi,
i've got two tables, one containing a foreign key to the other.
Table player and table teams. a player has a foreign key key to one team in the teams table.
now: how do i have to design the hbm.xml file and the corresponding c#-classes?
do i have to make something special in the spring.config file?
Could somebody post an example?
Thank you,
winx
Mark Pollack
04-04-2007, 04:02 PM
Hi,
Achieving this goal does not involve anything Spring specifc other than pointing to the NHibernate mapping files that express this relationship. If you look at the Northwind example in the Spring NHibernate distrubution you will find the two files, Customer.hbm.xml and Orders.hbm.xml. The corresponding Orders table has a foreign key to the Customers table, this probably matches what you have with the player and teams table. You can use this as a working example and transliterate to your own case.
However, the Northwind example is not a NHibernate tutorial per-se. I uggest you take a look at 'dedicated' NHibernate tutorials. Google for them, you will find quite a few. The one from the NHibernate folks themselves is here (http://nhibernate.sourceforge.net/NHibernateEg/). The NHibernate forums (http://forums.hibernate.org/viewforum.php?f=25&sid=1eaa7c14d189bcd261db5865ac497f6c) are also a good place to get help w.r.t to 'raw' NHibernate usage.
Cheers,
Mark
boriska
04-05-2007, 09:56 AM
Hello,
you can try to use e.g. the mygeneration http://www.mygenerationsoftware.com
tool to generate hbm.xml files with all corresponding c#-classes.
There are a lot of nhibernate templates, so you can just do it!:)
May be you have to change something after generation...
Regards,
Boris
vBulletin® v3.7.3, Copyright ©2000-2009, Jelsoft Enterprises Ltd.