I forgot the usual question... *Are you ConfORM ?*
On Tue, Jul 13, 2010 at 6:27 PM, Fabio Maulo <[email protected]> wrote: > The ConfORM mapping > public void MapDomain(ObjectRelationalMapper orm) > { > orm.Patterns.PoidStrategies.Add(new IdentityPoidPattern()); > orm.TablePerClass(new []{typeof(Category), typeof(Item)}); > } > > > The XML mapping (only to show it because ConfORM does not give it to NH) > > <hibernate-mapping xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" > xmlns:xsd="http://www.w3.org/2001/XMLSchema" > namespace="TryConfORM.PatrickPlattes" assembly="TryConfORM" > xmlns="urn:nhibernate-mapping-2.2"> > <class name="Category"> > <id name="Id" access="nosetter.camelcase" type="Int32"> > <generator class="identity" /> > </id> > <property name="Name" /> > <bag name="Items" inverse="true" cascade="all,delete-orphan"> > <key column="CategoryId" on-delete="cascade" /> > <one-to-many class="Item" /> > </bag> > </class> > <class name="Item"> > <id name="Id" access="nosetter.camelcase" type="Int32"> > <generator class="identity" /> > </id> > <list name="Tags" table="ItemTags"> > <key column="ItemId" /> > <list-index /> > <element type="String" /> > </list> > <property name="Name" /> > <many-to-one name="Category" column="CategoryId" /> > </class> > </hibernate-mapping> > The script > > create table Category ( > Id INT IDENTITY NOT NULL, > Name NVARCHAR(255) null, > primary key (Id) > ) > > create table Item ( > Id INT IDENTITY NOT NULL, > Name NVARCHAR(255) null, > CategoryId INT null, > primary key (Id) > ) > > create table ItemTags ( > ItemId INT not null, > id NVARCHAR(255) null, > idx INT not null, > primary key (ItemId, idx) > ) > > alter table Item > add constraint FKBCDC2F9520E4461C > foreign key (CategoryId) > references Category > on delete cascade > > alter table ItemTags > add constraint FK1DD188E0255E90A6 > foreign key (ItemId) > references Item > > As you can see, no duplication of FK. > > On Tue, Jul 13, 2010 at 4:53 PM, Fabio Maulo <[email protected]> wrote: > >> I'll try you little domain with ConfORM and we will see what happen >> >> >> On Tue, Jul 13, 2010 at 4:16 AM, Parity >> <[email protected]>wrote: >> >>> Hello, >>> >>> I use a really simple mapping to test many-to-one on the one side and >>> one-to-many on the other side associations. I use hbm2ddl to generate >>> the postgresql database, but i think there is something wrong. >>> >>> In this example i use items and put them into categories. This is my >>> mapping an cs: >>> >>> Item.hbm.xml >>> <?xml version="1.0" encoding="utf-8" ?> >>> <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" default- >>> cascade="all"> >>> <class name="WpfApplication1.Item, WpfApplication1"> >>> <id name="id" access="field"> >>> <generator class="native" /> >>> </id> >>> <property name="Name" /> >>> <many-to-one name="Category" /> >>> </class> >>> </hibernate-mapping> >>> >>> >>> Category.hbm.xml >>> <?xml version="1.0" encoding="utf-8" ?> >>> <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" default- >>> cascade="all"> >>> <class name="WpfApplication1.Category, WpfApplication1"> >>> <id name="Id"> >>> <generator class="native" /> >>> </id> >>> <property name="Name" /> >>> <list name="Items"> >>> <key/> >>> <index/> >>> <one-to-many class="WpfApplication1.Item, WpfApplication1"/> >>> </list> >>> </class> >>> </hibernate-mapping> >>> >>> >>> Item.cs >>> public class Item { >>> private int id; >>> private IList<String> tags = new List<String>(); >>> >>> public virtual String Name { get; set; } >>> >>> public Category Category { get; set; } >>> } >>> >>> >>> Category.cs >>> public class Category { >>> public IList items = new List<Item>(); >>> public virtual String Name { get; set; } >>> public virtual int Id { get; private set; } >>> >>> public virtual IList Items { >>> get { return items; } >>> set { items = value; } >>> } >>> >>> public void AddItem(Item i) { >>> i.Category = this; >>> items.Add(i); >>> } >>> } >>> >>> >>> This results in the following database structure: >>> CREATE TABLE category ( >>> id serial NOT NULL, >>> "name" character varying(255), >>> CONSTRAINT category_pkey PRIMARY KEY (id) >>> ) >>> CREATE TABLE item ( >>> id serial NOT NULL, >>> "name" character varying(255), >>> category integer, >>> idx integer, >>> CONSTRAINT item_pkey PRIMARY KEY (id), >>> CONSTRAINT fk742dc1781c9215d5 FOREIGN KEY (category) >>> REFERENCES category (id) MATCH SIMPLE >>> ON UPDATE NO ACTION ON DELETE NO ACTION, >>> CONSTRAINT fk742dc178d73c8956 FOREIGN KEY (id) >>> REFERENCES category (id) MATCH SIMPLE >>> ON UPDATE NO ACTION ON DELETE NO ACTION >>> ) >>> >>> I don't understand why there is the second FK (fk742dc178d73c8956). >>> And it fails if you want to add a second item to a cetegory. >>> >>> Are I'm doing anything wrong? I could send you a working vs projekt if >>> you wish. >>> >>> Thank you, >>> Patrick >>> >>> -- >>> 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 >> >> > > > -- > Fabio Maulo > > -- 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.
