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

-- 
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.

Reply via email to