views:

30

answers:

0

HI all,

I'm new to hibernate and I don't know how to handle correctly the updating of items on a one-to-many relation. My scenarion whould be:

class image { ILIst Relations;

}

class Mapping { Image Parent; OwnerId; OwnerType;

}

When I want to change the images attached to a owner I do: for each 'mappings for Owner X' { delete(mapping)

}

for all new image { image.Relations.add(new image-owner relation) save image

}

Unfortunately this end with a "deleted instance passed to merge[Mapping#]" error.

The Save is done using Session.Persist(). The Delete is done using Session.Delete()

The NH mapping is done through FluentNH, where on the ImageMap class I have HasMany(x => x.Mappings) .KeyColumn("ImageId") .ForeignKeyConstraintName("FK_ImageMapping") .Cascade .AllDeleteOrphan();

Any ideas?

Thanks, florin