-->
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.  [ 2 posts ] 
Author Message
 Post subject: help with cascade
PostPosted: Sat Feb 10, 2007 4:40 pm 
Newbie

Joined: Fri Nov 17, 2006 11:32 am
Posts: 13
I have something like this:
Code:
class A {
private List<B> lotOfBs=new ArrayList;
public void deleteOneB(B b){
        lotOfBs.remove(b);
        this.save();
}
public void save(){
        Session session = HibernateUtil.getSessionFactory().getCurrentSession();
   session.beginTransaction();
   session.saveOrUpdate(this);
   session.getTransaction().commit();
}
//oid declaration, getter and setter
}

this is more or less the mapping
Code:
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping>
  <class table="a" lazy="false" name="A">
    <id column="a_id" name="oid">
      <generator class="native"/>
    </id>
    <list lazy="false" cascade="all,delete-orphan" name="lotOfBs">
      <key column="a_id"/>
      <index column="position"/>
      <one-to-many class="B"/>
    </list>
  </class>
</hibernate-mapping>

The problem is that B is not deleted from the DB. I don't know why the cascade doesn't delete it.

I also tried to put "session.delete(b)", but when I load A the collection has null in B's position.

i also tried to delete B and then update A, but the following exception was thrown
org.hibernate.StaleStateException: Batch update returned unexpected row count from update: 0 actual row count: 0 expected: 1
due to I was trying to delete B twice.
Any clue?
Thanks
Neuquino

_________________
Neuquino
"Keep on trying and get better every day" (Queen)


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 12, 2007 5:18 am 
Newbie

Joined: Mon Feb 12, 2007 5:15 am
Posts: 1
Shouldn't
cascade="all,delete-orphan"
be
cascade="all-delete-orphan"


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.