The problem is it:
I have a class ItemVersionEntitythat has a list of ItemVersionAttachmentRel, each of ItemVersionAttachmentRel has a ItemVersionEntity and ItemAttachmentEntity, this class is only the relationship between ItemVersionEntity and ItemAttachmentEntity, it was created to solve the problem with database, because i don't want to save in the database the same attachment with diferent versions, that's why it was created.
So, there is no problem to insert a new ItemVersionAttachmentRel in the database, because when i create a new one, the ItemVersionEntity is new and the ItemAttachmentEntity is new too. But when i try to update one ItemVersionAttachmentRel, the ItemVersion is new, but ItemAttachmentEntity continue the same, include with the same id, because i make a reference of this object. So when i ask to update, the hibernate gives to me this error message:
"a different object with the same identifier value was already associated with the session: , of class ItemAttachmentEntity"
Class ItemVersionEntity:
private IList<ItemVersionAttachmentRel> _attachments;
public IList<ItemVersionAttachmentRel> Attachments
{
get { return _attachments; }
set { _attachments = value; }
}
Class ItemVersionAttachmentRel:
private ItemVersionEntity _itemVersion;
public ItemVersionEntity ItemVersion
{
get{ return _itemVersion; }
set{ _itemVersion = value; }
}
private ItemAttachmentEntity _itemAttachment;
public ItemAttachmentEntity ItemAttachment
{
get { return _itemAttachment; }
set { _itemAttachment = value; }
Class ItemAttachmentEntity:
// nothing especial
// only string and int
The Mapping:
ItemVersion XML:
<bag name="Attachments" cascade="all-delete-orphan" inverse="true">
<key column="ItemVersion_ID"/>
<one-to-many class="ItemVersionAttachmentRel" />
</bag>
ItemVersionAttachment XML:
<many-to-one name="ItemVersion" class="ItemVersionEntity" >
<column name="ItemVersion_ID" not-null="true"/>
</many-to-one>
<many-to-one name="ItemAttachment" class="ItemAttachmentEntity" cascade="all-delete-orphan" update="false">
<column name="ItemAttachment_ID" not-null="true"/>
</many-to-one>
I want to insert a newVersion with one existent attachment in the database.
I want to insert using cascade, but there is one of dependent object (ItemAttachmentEntity) that already exist in the databse, so i only want that hibernate do not try to insert this object only point to him.
|