The difference is that I don't have a many to many relationship. A "B" entities can have only one "A" object
On Jan 27, 5:14 pm, Shadowboxer <[email protected]> wrote: > Hi, > > I have something similar in my web app. I did it like this: > > Class A mapping: > > <?xml version="1.0" encoding="utf-8" ?> > <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"> > <class name="A" table="table_A" > > > <id name="Code" type="Int32" > > <column name="id" sql-type="integer" not-null="true" > unique="true" /> > <generator class="identity" /> > </id> > <property name="Name" type="String"> > <column name="name" length="100" sql-type="varchar" not- > null="true" /> > </property> > > <set name="B" lazy="true" cascade="save-update" table="table_AB"> > <key column="idA" /> > <many-to-many class="B" column="idB"/> > </set> > > </class> > </hibernate-mapping> > > Class B mapping: > > <?xml version="1.0" encoding="utf-8" ?> > <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"> > <class name="B" table="table_B" > > <id name="Code" type="Int32"> > <column name="id" sql-type="integer" not-null="true" > unique="true" /> > <generator class="identity" /> > </id> > > <property name="Name" type="String"> > <column name="name" length="100" sql-type="varchar" not- > null="true" /> > </property> > > <set name="A" lazy="true" cascade="save-update" table="table_AB"> > <key column="idB"/> > <many-to-many class="A" column="idA"/> > </set> > > </class> > </hibernate-mapping> > > Hope it helps > > On Jan 27, 10:49 am, Dana Efros <[email protected]> wrote: > > > Hi. I have to 2 entities: > > > class A{ > > int id; > > string name;} > > > class B{ > > int id; > > A refObj; > > string name;} > > > How can I map this 2 classes so I will have 3 tables: > > table A with 2 columns: id and name > > table B with 2 columns: id and name > > table AB with 2 columns: idA and idB (idB is unique) > > > In the AB table I need to have a row only when refObj will not be > > null.The field refObj from the B entity will have values only > > occasionally and I don't want to have a column in the B table with > > null value for almost all the rows > > > With a many to many relations I know how, but with a reference ... > > Thanks -- 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.
