-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Problem with many-to-one cascade="all-delete-orphan&quo
PostPosted: Tue Apr 03, 2007 3:11 pm 
Newbie

Joined: Tue Apr 03, 2007 1:17 pm
Posts: 1
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.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.