To know the answer, perhaps, the domain is required. If you will generate the DB through NH the domain is enough if not, to know if the mapping is correct, we need the schema too.
On Mon, Nov 8, 2010 at 1:15 PM, Michael Delva <[email protected]> wrote: > Hello everybody, > > I'm still low on the learning curve of NH, and I have some problems to > correctly map my entities. > > Here is what the entities I have, and their relationships: > > A Team entity, which has multiple TeamRoster. Each TeamRoster contains > a list of references to Player, and with each reference, stores the > number of the player. > A Match entity, which has 2 references to Team, and 2 references to > Roster. > > Here, TeamRoster inherits from Roster, and just add some specific > properties it needs. > > Here are the mappings of these entities, created with FluentNH: > > * Team > > <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" default- > access="property" auto-import="true" default-cascade="none" default- > lazy="true"> > <class xmlns="urn:nhibernate-mapping-2.2" mutable="true" > name="Emidee.CommonEntities.Team, Emidee.CommonEntities, > Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" table="Teams"> > <id name="Id" type="System.Int32, mscorlib, Version=4.0.0.0, > Culture=neutral, PublicKeyToken=b77a5c561934e089"> > <column name="Id" /> > <generator class="increment" /> > </id> > <set cascade="all-delete-orphan" inverse="true" name="Rosters" > mutable="true"> > <key> > <column name="Team_id" /> > </key> > <one-to-many class="Emidee.CommonEntities.TeamRoster, > Emidee.CommonEntities, Version=1.0.0.0, Culture=neutral, > PublicKeyToken=null" /> > </set> > <set inverse="true" name="MatchesAtHome" mutable="true"> > <key> > <column name="HomeTeam_id" /> > </key> > <one-to-many class="Emidee.CommonEntities.Match, > Emidee.CommonEntities, Version=1.0.0.0, Culture=neutral, > PublicKeyToken=null" /> > </set> > <set inverse="true" name="MatchesOnRoad" mutable="true"> > <key> > <column name="RoadTeam_id" /> > </key> > <one-to-many class="Emidee.CommonEntities.Match, > Emidee.CommonEntities, Version=1.0.0.0, Culture=neutral, > PublicKeyToken=null" /> > </set> > </class> > </hibernate-mapping> > > * Roster > > <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" default- > access="property" auto-import="true" default-cascade="none" default- > lazy="true"> > <class xmlns="urn:nhibernate-mapping-2.2" mutable="true" > name="Emidee.CommonEntities.Roster, Emidee.CommonEntities, > Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" > table="`Roster`"> > <id name="Id" type="System.Int32, mscorlib, Version=4.0.0.0, > Culture=neutral, PublicKeyToken=b77a5c561934e089"> > <column name="Id" /> > <generator class="increment" /> > </id> > <set cascade="all-delete-orphan" inverse="true" name="Players" > mutable="true"> > <key> > <column name="Roster_id" /> > </key> > <one-to-many class="Emidee.CommonEntities.PlayerInTeam, > Emidee.CommonEntities, Version=1.0.0.0, Culture=neutral, > PublicKeyToken=null" /> > </set> > <many-to-one class="Emidee.CommonEntities.Team, > Emidee.CommonEntities, Version=1.0.0.0, Culture=neutral, > PublicKeyToken=null" name="Team"> > <column name="Team_id" not-null="true" /> > </many-to-one> > <joined-subclass name="Emidee.CommonEntities.TeamRoster, > Emidee.CommonEntities, Version=1.0.0.0, Culture=neutral, > PublicKeyToken=null" table="`TeamRoster`"> > <key> > <column name="Roster_id" /> > </key> > <property name="IsDefault" type="System.Boolean, mscorlib, > Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"> > <column name="IsDefault" length="250" not-null="true" /> > </property> > <property name="Name" type="System.String, mscorlib, > Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"> > <column name="Name" length="250" not-null="true" /> > </property> > <many-to-one class="Emidee.CommonEntities.Team, > Emidee.CommonEntities, Version=1.0.0.0, Culture=neutral, > PublicKeyToken=null" name="Team"> > <column name="Team_id" not-null="true" /> > </many-to-one> > </joined-subclass> > </class> > </hibernate-mapping> > > * Match > > <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" default- > access="property" auto-import="true" default-cascade="none" default- > lazy="true"> > <class xmlns="urn:nhibernate-mapping-2.2" mutable="true" > name="Emidee.CommonEntities.Match, Emidee.CommonEntities, > Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" > table="Matches"> > <id name="Id" type="System.Int32, mscorlib, Version=4.0.0.0, > Culture=neutral, PublicKeyToken=b77a5c561934e089"> > <column name="Id" /> > <generator class="increment" /> > </id> > <many-to-one class="Emidee.CommonEntities.Championship, > Emidee.CommonEntities, Version=1.0.0.0, Culture=neutral, > PublicKeyToken=null" name="Championship"> > <column name="Championship_id" /> > </many-to-one> > <many-to-one class="Emidee.CommonEntities.Team, > Emidee.CommonEntities, Version=1.0.0.0, Culture=neutral, > PublicKeyToken=null" name="HomeTeam"> > <column name="HomeTeam_id" not-null="true" /> > </many-to-one> > <many-to-one class="Emidee.CommonEntities.Team, > Emidee.CommonEntities, Version=1.0.0.0, Culture=neutral, > PublicKeyToken=null" name="RoadTeam"> > <column name="RoadTeam_id" not-null="true" /> > </many-to-one> > <many-to-one cascade="save-update" > class="Emidee.CommonEntities.Roster, Emidee.CommonEntities, > Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" > name="HomeRoster"> > <column name="HomeRoster_id" /> > </many-to-one> > <many-to-one cascade="save-update" > class="Emidee.CommonEntities.Roster, Emidee.CommonEntities, > Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" > name="RoadRoster"> > <column name="RoadRoster_id" /> > </many-to-one> > </class> > </hibernate-mapping> > > Is my Roster mapping correct? I've tried a lot of various combinations > to make this work, and I'd like to have your point of view about that. > > And my other question concerns the relationships between Match and > Roster. One Match references 2 Rosters (one for each team). Is the > many-to-one relationship OK? I'm not sure about that. Should I use a > one-to-one relationship? > > Thanks in advance > > Mike > > -- > You received this message because you are subscribed to the Google Groups > "nhusers" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]<nhusers%[email protected]> > . > For more options, visit this group at > http://groups.google.com/group/nhusers?hl=en. > > -- Fabio Maulo -- You received this message because you are subscribed to the Google Groups "nhusers" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/nhusers?hl=en.
