Fabio,
In case the mapping were correct, just having the Item entity and the
ItemImage mapped as a component, the idbag ID is not mapped to the
component
but still nhibernate use this ID to delete one ItemImage. Is this ID
only available for nhibernate use?
Lets say in a webapp, you have a page showing the details of one Item
and the list of ItemImage it has. The list has a link to edit. I would
have to use some other properties of ItemImage to locate the instance
in the Item.Images collection. Am I right?

Regards,
William



On Wed, Jan 6, 2010 at 8:00 PM, Fabio Maulo <[email protected]> wrote:
> component does not have id.
> entity has id.
> In the collection you are using the class as component and then you having
> the same class as entity.
> Your problem look more like a mixed-salad with chocolate.
>
>
> 2010/1/6 Michael Vodep <[email protected]>
>>
>> Hi
>>
>> I have done some examples from "NHibernate in Action" and got a
>> strange problem:
>>
>> * * * * * * * * * * * * * * * * * * * * * * * * * * *  ~~ CODE ~~ * *
>> * * * * * * * * * * * * * * * * * * * * * * * * *
>> namespace ConsoleApplication3
>> {
>>    public class Item
>>    {
>>        public virtual Int64 ItemId { get; set; }
>>        public virtual string Name { get; set; }
>>
>>        private IList<ItemImage> images = new List<ItemImage>();
>>        public virtual IList<ItemImage> Images
>>        {
>>            get { return this.images; }
>>            set { this.images = value; }
>>        }
>>    }
>> }
>>
>> <?xml version="1.0" encoding="utf-8" ?>
>> <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
>> assembly="ConsoleApplication3" namespace="ConsoleApplication3">
>>  <class name="Item" table="item">
>>    <id name="ItemId" type="Int64" column="itemid">
>>      <generator class="native"/>
>>    </id>
>>    <property name="Name" column="name" />
>>
>>    <idbag name="Images"
>>      lazy="true"
>>      table="item_image">
>>      <collection-id type="Int64" column="id">
>>        <generator class="native"/>
>>      </collection-id>
>>      <key column="itemid"/>
>>      <composite-element class="ConsoleApplication3.ItemImage,
>> ConsoleApplication3">
>>        <parent name="Item"/>
>>        <property name="Filename" column="filename" not-null="true"/>
>>        <property name="Zeitpunkt" column="zeitpunkt" not-null="true"/
>> >
>>        <property name="Menge" column="menge" not-null="true"/>
>>      </composite-element>
>>    </idbag>
>>
>>  </class>
>> </hibernate-mapping>
>>
>> namespace ConsoleApplication3
>> {
>>    public class ItemImage
>>    {
>>        public virtual Int64 Id { get; set; }
>>        public virtual Item Item { get; set; }
>>        public virtual string Filename { get; set; }
>>        public virtual DateTime Zeitpunkt { get; set; }
>>        public virtual int Menge { get; set; }
>>    }
>> }
>>
>> <?xml version="1.0" encoding="utf-8" ?>
>> <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
>> assembly="ConsoleApplication3" namespace="ConsoleApplication3">
>>  <class name="ItemImage" table="item_image">
>>    <id name="Id" type="Int64" column="id">
>>      <generator class="native"/>
>>    </id>
>>
>>    <property name="Filename" column="filename" not-null="true"/>
>>    <property name="Zeitpunkt" column="zeitpunkt" not-null="true"/>
>>    <property name="Menge" column="menge" not-null="true"/>
>>  </class>
>> </hibernate-mapping>
>>
>> * * * * * * * * * * * * * * * * * * * * * * * * * * *  ~~ CODE END ~~
>> * * * * * * * * * * * * * * * * * * * * * * * * * * *
>>
>> If i do a simple insert and retreive the data:
>>
>> * * * * * * * * * * * * * * * * * * * * * * * * * * *  ~~ CODE ~~ * *
>> * * * * * * * * * * * * * * * * * * * * * * * * *
>> Item item = new Item();
>>
>> item.Name = "TEST";
>>
>> ItemImage img1 = new ItemImage() { Filename = Guid.NewGuid().ToString
>> (), Menge = 99, Zeitpunkt = DateTime.Now };
>> ItemImage img2 = new ItemImage() { Filename = Guid.NewGuid().ToString
>> (), Menge = 105, Zeitpunkt = DateTime.Now + TimeSpan.FromMinutes(10)};
>>
>> item.Images.Add(img1);
>> item.Images.Add(img2);
>>
>> session.Save(item);
>> trans.Commit();
>>
>> Item item2 = session.Get<Item>(item.ItemId);
>>
>> foreach (ItemImage i in item2.Images)
>> {
>>    Console.WriteLine(i.Id + " " + i.Menge + " " + i.Zeitpunkt + " " +
>> i.Filename);
>> }
>>
>> Console.ReadKey();
>>
>> * * * * * * * * * * * * * * * * * * * * * * * * * * *  ~~ CODE END ~~
>> * * * * * * * * * * * * * * * * * * * * * * * * * * *
>>
>> In the foreach loop the Id of ItemImage is not set. So if i use it as
>> a POCO i have no way to do a UPDATE because i lost the IDs. Does
>> anybody know how to fix that?
>>
>> Thanks a lot
>> Best regards
>> Michael
>>
>> --
>> 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.
>>
>>
>>
>
>
>
> --
> 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.
>
>
-- 
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