-->
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.  [ 9 posts ] 
Author Message
 Post subject: Problem with cascade delete in one-to-one
PostPosted: Mon Jun 04, 2007 5:42 am 
Newbie

Joined: Wed May 23, 2007 6:11 am
Posts: 5
Hi all,

Sorry for newbie question but I have a problem with cascade delete.
See my mapping.
There is "one to one" relation between CartItem and CartConten, but it seems that cascade delete does not work. It complains that CartContent still references from CartItem.

Thanks in advance for help.

<class name="CartItem">
<id name="id" type="long">
<generator class="native"/>
</id>
<many-to-one name="cart" class="Cart" column="cartId" not-null="true" cascade="all, delete"/>

<many-to-one name="content" class="CartContent" cascade="all,delete">
<column name="contentid" not-null="true"
unique="true"></column>
</many-to-one>
</class>

<class name="CartContent" table="CartContent">
<id name="id">
<generator class="native"/>
</id>
</class>


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 04, 2007 8:17 am 
Expert
Expert

Joined: Thu Sep 22, 2005 10:29 am
Posts: 285
Location: Almassera/Valencia/Spain/EU/Earth/Solar system/Milky Way/Local Group/Virgo Supercluster
Where's the one-to-one?

Post your Java code.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 04, 2007 9:11 am 
Newbie

Joined: Wed May 23, 2007 6:11 am
Posts: 5
one-to-one is the following regarding Hibernate manual (http://www.hibernate.org/hib_docs/v3/re ... tional-121)

<many-to-one name="content" class="CartContent" cascade="all,delete">
<column name="contentid" not-null="true"
unique="true"></column>
</many-to-one>


public class CartItem {
private CartContent content;
private Long id;
private Cart cart;
}

public interface CartContent {

public Long getId();

public void setId(Long id);
}


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 04, 2007 10:13 am 
Expert
Expert

Joined: Thu Sep 22, 2005 10:29 am
Posts: 285
Location: Almassera/Valencia/Spain/EU/Earth/Solar system/Milky Way/Local Group/Virgo Supercluster
When I told you to post the Java code, I wanted to mean the Java code that throws the exception or that doesn't work properly.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 04, 2007 3:48 pm 
Beginner
Beginner

Joined: Mon May 21, 2007 5:22 pm
Posts: 27
Location: Salt Lake City
cascade="delete-orphan"


try this :)

_________________
Try 'N' Enjoy !!
Rahul

If helpful do rating ....


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 04, 2007 5:17 pm 
Newbie

Joined: Wed May 23, 2007 6:11 am
Posts: 5
pepelnm wrote:
When I told you to post the Java code, I wanted to mean the Java code that throws the exception or that doesn't work properly.


actually it is code from the TestCase using DBUnit, it fails after colling Transaction.commit() in tearDown()

Cart cartToBeDeleted = cartDao.findById(dbCart.getId());

cartDao.delete(cartToBeDeleted);

Session session = sessionFactory.getCurrentSession();
assertNull(session.get(Cart.class, dbCart.getId()));


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 04, 2007 5:17 pm 
Newbie

Joined: Wed May 23, 2007 6:11 am
Posts: 5
pepelnm wrote:
When I told you to post the Java code, I wanted to mean the Java code that throws the exception or that doesn't work properly.


actually it is code from the TestCase using DBUnit, it fails after colling Transaction.commit() in tearDown()

Cart cartToBeDeleted = cartDao.findById(dbCart.getId());

cartDao.delete(cartToBeDeleted);

Session session = sessionFactory.getCurrentSession();
assertNull(session.get(Cart.class, dbCart.getId()));


4-Jun-2007 23:16:00 org.hibernate.util.JDBCExceptionReporter logExceptions
SEVERE: ERROR: update or delete on table "cartcontent" violates foreign key constraint "fk4393e735379077a" on table "cartitem"
Detail: Key (id)=(3002) is still referenced from table "cartitem".


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 04, 2007 5:21 pm 
Newbie

Joined: Wed May 23, 2007 6:11 am
Posts: 5
rahul dongre wrote:
cascade="delete-orphan"
try this :)


Unfortunatelly, it is not supported for "one to one"
I"ve tried it anyway


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 05, 2007 8:15 pm 
Expert
Expert

Joined: Thu Sep 22, 2005 10:29 am
Posts: 285
Location: Almassera/Valencia/Spain/EU/Earth/Solar system/Milky Way/Local Group/Virgo Supercluster
What sort of object are you deleting (cartToBeDeleted)?
A Cart, a CartContent, a CartItem????

You talked about a
Quote:
"one to one" relation between CartItem and CartConten

but in your Java code you are deleting a Cart object.

Can you explain that a bit?


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

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.