-->
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.  [ 5 posts ] 
Author Message
 Post subject: cascade delete does not delete child elements
PostPosted: Thu Jan 19, 2006 6:28 am 
Newbie

Joined: Wed Dec 14, 2005 6:50 am
Posts: 17
We are stuck in the following problem:
In a parent-child mapping situation we use cascade (Ibistarget=parent, Ibisaction=Child), so the children are managed by the parent. This works fine as long as we insert,update any child or parent. But if we remove a child from the set in parent the child won't be removed. Actually there is no delete sent to the db. We did the example from capture 21. (online-dok) step by step. After no success we tried some other mapping settings but didn't help either. If we expliclity delete the child, the following exception occurs:
org.hibernate.ObjectDeletedException: The object with that id was deleted: [ch.ascom.pasis.common.model.Ibisaction#16447]
while JUnit says: org.hibernate.ObjectDeletedException: deleted object would be re-saved by cascade (remove deleted object from associations): [ch.ascom.pasis.common.model.Ibisaction#16447]
We can't figure out, what we are doing wrong!

Any help would be appreciated!

The code is a junit test case;
The call clearDb(); deletes everything in the database.
SetUp() creates a session, tearDown() closes it.

Hope didn't post too much stuff, but so i get sure every connected information is available:

Hibernate version: 3.1
Name and version of the database you are using: HSQLDB 1.8.0
Mapping documents:
Parent:
Code:
   <class name="ch.ascom.pasis.common.model.Ibistarget"
      table="ibistarget" lazy="true">
      <meta attribute="implement-equals" inherit="false">true</meta>

      <id name="ibisTargetId" type="java.lang.Integer"
         column="IbisTargetID">

         <generator
            class="ch.ascom.pasis.common.hibernate.PasisIdGenerator">
            <param name="table">keyallocation</param>
            <param name="column">LastKey</param>
         </generator>
      </id>

      <property name="targetNumber" type="int" column="TargetNumber"
         not-null="true" length="11" />
      <property name="shortName" type="java.lang.String"
         column="ShortName" not-null="true" length="31" />

      <!-- Associations -->

      <!-- bi-directional one-to-many association to IbisactionAbstract -->

      <set
         name="ibisactions"
         lazy="true"
         cascade="all-delete-orphan"
         inverse="true">
         <key>
            <column name="IbisTargetID" not-null="true" />
         </key>

         <one-to-many class="ch.ascom.pasis.common.model.Ibisaction" />
      </set>

   </class>

Parent pojo:
Code:
public class Ibistarget implements Serializable {

    private Integer ibisTargetId;
    private int targetNumber;
    private String shortName;
    private Set ibisactions;

    /** full constructor */
    public Ibistarget(int targetNumber, String shortName, Set ibisactions) {
        this.targetNumber = targetNumber;
        this.shortName = shortName;
        this.ibisactions = ibisactions;
    }

    /** default constructor */
    public Ibistarget() {
    }

    public Integer getIbisTargetId() {
        return this.ibisTargetId;
    }

    public void setIbisTargetId(Integer ibisTargetId) {
        this.ibisTargetId = ibisTargetId;
    }

    public int getTargetNumber() {
        return this.targetNumber;
    }

    public void setTargetNumber(int targetNumber) {
        this.targetNumber = targetNumber;
    }

    public String getShortName() {
        return this.shortName;
    }

    public void setShortName(String shortName) {
        this.shortName = shortName;
    }

    public Set getIbisactions() {
        return this.ibisactions;
    }

    public void setIbisactions(Set ibisactions) {
        this.ibisactions = ibisactions;
    }

    public String toString() {
        return new ToStringBuilder(this)
            .append("ibisTargetId", getIbisTargetId())
            .toString();
    }

    public boolean equals(Object other) {
        if ( (this == other ) ) return true;
        if ( !(other instanceof Ibistarget) ) return false;
        Ibistarget castOther = (Ibistarget) other;
        return new EqualsBuilder()
            .append(this.getIbisTargetId(), castOther.getIbisTargetId())
            .isEquals();
    }

    public int hashCode() {
        return new HashCodeBuilder()
            .append(getIbisTargetId())
            .toHashCode();
    }
}

Child:
Code:
   <class name="ch.ascom.pasis.common.model.Ibisaction"
      table="ibisaction" lazy="true">
      <meta attribute="implement-equals" inherit="false">true</meta>

      <id name="ibisActionId" type="java.lang.Integer"
         column="IbisActionID">

         <generator
            class="ch.ascom.pasis.common.hibernate.PasisIdGenerator">
            <param name="table">keyallocation</param>
            <param name="column">LastKey</param>
         </generator>
      </id>

      <property name="shortName" type="java.lang.String"
         column="ShortName" not-null="false" length="31" />

      <!-- Associations -->

      <!-- bi-directional many-to-one association to IbispayloadAbstract -->
      <many-to-one name="ibispayload"
         class="ch.ascom.pasis.common.model.Ibispayload" not-null="false">
         <column name="IbisPayloadID" />
      </many-to-one>
      <!-- bi-directional many-to-one association to IbistargetAbstract -->
      <many-to-one name="ibistarget" column="IbisTargetID" not-null="true"/>

   </class>

Child pojo:
Code:
public class Ibisaction implements Serializable, PersistentObject {

    private Integer ibisActionId;
    private String shortName;
    private Ibispayload ibispayload;
    private Ibistarget ibistarget;

    /** full constructor */
    public Ibisaction(String shortName, Ibispayload ibispayload, Ibistarget ibistarget) {
        this.shortName = shortName;
        this.ibispayload = ibispayload;
        this.ibistarget = ibistarget;
    }

    /** default constructor */
    public Ibisaction() {
    }

    public Integer getIbisActionId() {
        return this.ibisActionId;
    }

    public void setIbisActionId(Integer ibisActionId) {
        this.ibisActionId = ibisActionId;
    }

    public String getShortName() {
        return this.shortName;
    }

    public void setShortName(String shortName) {
        this.shortName = shortName;
    }

    public Ibispayload getIbispayload() {
        return this.ibispayload;
    }

    public void setIbispayload(Ibispayload ibispayload) {
        this.ibispayload = ibispayload;
    }

    public Ibistarget getIbistarget() {
        return this.ibistarget;
    }

    public void setIbistarget(Ibistarget ibistarget) {
        this.ibistarget = ibistarget;
    }

    public String toString() {
        return new ToStringBuilder(this,ToStringStyle.SIMPLE_STYLE )
            .append("ibisActionId", getIbisActionId())
            .append("ShortName", getShortName())
            .toString();
    }

    public boolean equals(Object other) {
        if ( (this == other ) ) return true;
        if ( !(other instanceof Ibisaction) ) return false;
        Ibisaction castOther = (Ibisaction) other;
        return new EqualsBuilder()
            .append(this.getIbisActionId(), castOther.getIbisActionId())
            .append(this.getShortName(), castOther.getShortName())
            .isEquals();
    }

    public int hashCode() {
        return new HashCodeBuilder()
            .append(getIbisActionId())
            .append(getShortName())
            .toHashCode();
    }
}


Code between sessionFactory.openSession() and session.close():
Code:
   public void testCollectionBehaviour() {
       clearDb();
       Transaction tx = session.beginTransaction();
       
       Ibistarget target = new Ibistarget(99,"Target 1",new HashSet());       
       Ibisaction action = new Ibisaction("Action 1",null,target);
       target.getIbisactions().add(action);
       Ibisaction action2 = new Ibisaction("Action 2",null,target);
       target.getIbisactions().add(action2);
       session.saveOrUpdate(target);
       tx.commit();
       tx = session.beginTransaction();
       Integer tid = target.getKey();
       Integer aid = action.getKey();
       
       logger.debug("Target and Action created");
       Ibistarget loadedTarget = (Ibistarget)session.get(Ibistarget.class,tid);
       assertEquals(target,loadedTarget);
       assertEquals(2,loadedTarget.getIbisactions().size());
              
       Ibisaction action3 = new Ibisaction("Action 3",null,target);
       target.getIbisactions().add(action3);
       tx.commit();
       logger.debug("Third action added");
       Ibistarget loadedTarget2 = (Ibistarget)session.get(Ibistarget.class,tid);
       assertEquals(3,loadedTarget2.getIbisactions().size());
       
              
       //session.delete(action);
       tx = session.beginTransaction();
       action = (Ibisaction)session.get(Ibisaction.class,aid);
       loadedTarget2.getIbisactions().remove(action);
       assertFalse(loadedTarget2.getIbisactions().contains(action));       
       tx.commit();
       logger.debug("First action removed");        
       Ibistarget loadedTarget3 = (Ibistarget)session.get(Ibistarget.class,tid);
       Ibisaction loadedAction = (Ibisaction)session.get(Ibisaction.class,aid);
       assertNull(loadedAction);
       assertEquals(2,loadedTarget3.getIbisactions().size());       
    }


Full stack trace of any exception that occurs: no exception

The generated SQL (show_sql=true): look at debug below
Debug level Hibernate log excerpt:
Code:
10:03:58,953 DEBUG TestHbmMapping:113 - Third action added
2844 [main] DEBUG ch.ascom.pasis.test.mapping.TestHbmMapping  - Third action added
2844 [main] DEBUG org.hibernate.event.def.DefaultLoadEventListener  - loading entity: [ch.ascom.pasis.common.model.Ibistarget#16433]
2844 [main] DEBUG org.hibernate.event.def.DefaultLoadEventListener  - attempting to resolve: [ch.ascom.pasis.common.model.Ibistarget#16433]
2844 [main] DEBUG org.hibernate.event.def.DefaultLoadEventListener  - resolved object in session cache: [ch.ascom.pasis.common.model.Ibistarget#16433]
2844 [main] DEBUG org.hibernate.jdbc.JDBCContext  - after autocommit
2844 [main] DEBUG org.hibernate.transaction.JDBCTransaction  - begin
2859 [main] DEBUG org.hibernate.transaction.JDBCTransaction  - current autocommit status: false
2859 [main] DEBUG org.hibernate.event.def.DefaultLoadEventListener  - loading entity: [ch.ascom.pasis.common.model.Ibisaction#16435]
2859 [main] DEBUG org.hibernate.event.def.DefaultLoadEventListener  - attempting to resolve: [ch.ascom.pasis.common.model.Ibisaction#16435]
2859 [main] DEBUG org.hibernate.event.def.DefaultLoadEventListener  - resolved object in session cache: [ch.ascom.pasis.common.model.Ibisaction#16435]
2859 [main] DEBUG org.hibernate.transaction.JDBCTransaction  - commit
2859 [main] DEBUG org.hibernate.impl.SessionImpl  - automatically flushing session
2859 [main] DEBUG org.hibernate.event.def.AbstractFlushingEventListener  - flushing session
2859 [main] DEBUG org.hibernate.event.def.AbstractFlushingEventListener  - processing flush-time cascades
2859 [main] DEBUG org.hibernate.engine.Cascades  - processing cascade ACTION_SAVE_UPDATE for: ch.ascom.pasis.common.model.Ibistarget
2859 [main] DEBUG org.hibernate.engine.Cascades  - cascade ACTION_SAVE_UPDATE for collection: ch.ascom.pasis.common.model.Ibistarget.ibisactions
2859 [main] DEBUG org.hibernate.engine.Cascades  - cascading to saveOrUpdate: ch.ascom.pasis.common.model.Ibisaction
2859 [main] DEBUG org.hibernate.event.def.AbstractSaveEventListener  - persistent instance of: ch.ascom.pasis.common.model.Ibisaction
2859 [main] DEBUG org.hibernate.event.def.DefaultSaveOrUpdateEventListener  - ignoring persistent instance
2859 [main] DEBUG org.hibernate.event.def.DefaultSaveOrUpdateEventListener  - object already associated with session: [ch.ascom.pasis.common.model.Ibisaction#16436]
2859 [main] DEBUG org.hibernate.engine.Cascades  - cascading to saveOrUpdate: ch.ascom.pasis.common.model.Ibisaction
2859 [main] DEBUG org.hibernate.event.def.AbstractSaveEventListener  - persistent instance of: ch.ascom.pasis.common.model.Ibisaction
2859 [main] DEBUG org.hibernate.event.def.DefaultSaveOrUpdateEventListener  - ignoring persistent instance
2859 [main] DEBUG org.hibernate.event.def.DefaultSaveOrUpdateEventListener  - object already associated with session: [ch.ascom.pasis.common.model.Ibisaction#16434]
2859 [main] DEBUG org.hibernate.engine.Cascades  - cascading to saveOrUpdate: ch.ascom.pasis.common.model.Ibisaction
2859 [main] DEBUG org.hibernate.event.def.AbstractSaveEventListener  - persistent instance of: ch.ascom.pasis.common.model.Ibisaction
2859 [main] DEBUG org.hibernate.event.def.DefaultSaveOrUpdateEventListener  - ignoring persistent instance
2859 [main] DEBUG org.hibernate.event.def.DefaultSaveOrUpdateEventListener  - object already associated with session: [ch.ascom.pasis.common.model.Ibisaction#16435]
2859 [main] DEBUG org.hibernate.engine.Cascades  - done cascade ACTION_SAVE_UPDATE for collection: ch.ascom.pasis.common.model.Ibistarget.ibisactions
2859 [main] DEBUG org.hibernate.engine.Cascades  - deleting orphans for collection: ch.ascom.pasis.common.model.Ibistarget.ibisactions
2859 [main] DEBUG org.hibernate.engine.Cascades  - done deleting orphans for collection: ch.ascom.pasis.common.model.Ibistarget.ibisactions
2859 [main] DEBUG org.hibernate.engine.Cascades  - done processing cascade ACTION_SAVE_UPDATE for: ch.ascom.pasis.common.model.Ibistarget
2859 [main] DEBUG org.hibernate.engine.Cascades  - processing cascade ACTION_SAVE_UPDATE for: ch.ascom.pasis.common.model.Ibisaction
2859 [main] DEBUG org.hibernate.engine.Cascades  - done processing cascade ACTION_SAVE_UPDATE for: ch.ascom.pasis.common.model.Ibisaction
2859 [main] DEBUG org.hibernate.engine.Cascades  - processing cascade ACTION_SAVE_UPDATE for: ch.ascom.pasis.common.model.Ibisaction
2859 [main] DEBUG org.hibernate.engine.Cascades  - done processing cascade ACTION_SAVE_UPDATE for: ch.ascom.pasis.common.model.Ibisaction
2875 [main] DEBUG org.hibernate.engine.Cascades  - processing cascade ACTION_SAVE_UPDATE for: ch.ascom.pasis.common.model.Ibisaction
2875 [main] DEBUG org.hibernate.engine.Cascades  - done processing cascade ACTION_SAVE_UPDATE for: ch.ascom.pasis.common.model.Ibisaction
2875 [main] DEBUG org.hibernate.event.def.AbstractFlushingEventListener  - dirty checking collections
2875 [main] DEBUG org.hibernate.engine.CollectionEntry  - Collection dirty: [ch.ascom.pasis.common.model.Ibistarget.ibisactions#16433]
2875 [main] DEBUG org.hibernate.event.def.AbstractFlushingEventListener  - Flushing entities and processing referenced collections
2875 [main] DEBUG org.hibernate.engine.Collections  - Collection found: [ch.ascom.pasis.common.model.Ibistarget.ibisactions#16433], was: [ch.ascom.pasis.common.model.Ibistarget.ibisactions#16433] (initialized)
2875 [main] DEBUG org.hibernate.event.def.AbstractFlushingEventListener  - Processing unreferenced collections
2875 [main] DEBUG org.hibernate.event.def.AbstractFlushingEventListener  - Scheduling collection removes/(re)creates/updates
2875 [main] DEBUG org.hibernate.event.def.AbstractFlushingEventListener  - Flushed: 0 insertions, 0 updates, 0 deletions to 4 objects
2875 [main] DEBUG org.hibernate.event.def.AbstractFlushingEventListener  - Flushed: 0 (re)creations, 1 updates, 0 removals to 1 collections
2875 [main] DEBUG org.hibernate.pretty.Printer  - listing entities:
2875 [main] DEBUG org.hibernate.pretty.Printer  - ch.ascom.pasis.common.model.Ibisaction{shortName=Action 1, ibispayload=null, ibisActionId=16435, ibistarget=ch.ascom.pasis.common.model.Ibistarget#16433}
2875 [main] DEBUG org.hibernate.pretty.Printer  - ch.ascom.pasis.common.model.Ibisaction{shortName=Action 2, ibispayload=null, ibisActionId=16434, ibistarget=ch.ascom.pasis.common.model.Ibistarget#16433}
2875 [main] DEBUG org.hibernate.pretty.Printer  - ch.ascom.pasis.common.model.Ibisaction{shortName=Action 3, ibispayload=null, ibisActionId=16436, ibistarget=ch.ascom.pasis.common.model.Ibistarget#16433}
2875 [main] DEBUG org.hibernate.pretty.Printer  - ch.ascom.pasis.common.model.Ibistarget{ibisTargetId=16433, shortName=Target 1, ibisactions=[ch.ascom.pasis.common.model.Ibisaction#16436, ch.ascom.pasis.common.model.Ibisaction#16434, ch.ascom.pasis.common.model.Ibisaction#16435], targetNumber=99}
2875 [main] DEBUG org.hibernate.event.def.AbstractFlushingEventListener  - executing flush
2875 [main] DEBUG org.hibernate.event.def.AbstractFlushingEventListener  - post flush
2875 [main] DEBUG org.hibernate.jdbc.JDBCContext  - before transaction completion
2875 [main] DEBUG org.hibernate.impl.SessionImpl  - before transaction completion
2875 [main] DEBUG org.hibernate.transaction.JDBCTransaction  - committed JDBC Connection
2875 [main] DEBUG org.hibernate.jdbc.JDBCContext  - after transaction completion
2875 [main] DEBUG org.hibernate.impl.SessionImpl  - after transaction completion
10:03:58,984 DEBUG TestHbmMapping:124 - First action removed
2875 [main] DEBUG ch.ascom.pasis.test.mapping.TestHbmMapping  - First action removed
2875 [main] DEBUG org.hibernate.event.def.DefaultLoadEventListener  - loading entity: [ch.ascom.pasis.common.model.Ibistarget#16433]
2875 [main] DEBUG org.hibernate.event.def.DefaultLoadEventListener  - attempting to resolve: [ch.ascom.pasis.common.model.Ibistarget#16433]
2891 [main] DEBUG org.hibernate.event.def.DefaultLoadEventListener  - resolved object in session cache: [ch.ascom.pasis.common.model.Ibistarget#16433]
2891 [main] DEBUG org.hibernate.jdbc.JDBCContext  - after autocommit
2891 [main] DEBUG org.hibernate.event.def.DefaultLoadEventListener  - loading entity: [ch.ascom.pasis.common.model.Ibisaction#16435]
2891 [main] DEBUG org.hibernate.event.def.DefaultLoadEventListener  - attempting to resolve: [ch.ascom.pasis.common.model.Ibisaction#16435]
2891 [main] DEBUG org.hibernate.event.def.DefaultLoadEventListener  - resolved object in session cache: [ch.ascom.pasis.common.model.Ibisaction#16435]
2891 [main] DEBUG org.hibernate.jdbc.JDBCContext  - after autocommit
2906 [main] DEBUG org.hibernate.event.def.AbstractFlushingEventListener  - flushing session
2906 [main] DEBUG org.hibernate.event.def.AbstractFlushingEventListener  - processing flush-time cascades
2906 [main] DEBUG org.hibernate.engine.Cascades  - processing cascade ACTION_SAVE_UPDATE for: ch.ascom.pasis.common.model.Ibistarget
2906 [main] DEBUG org.hibernate.engine.Cascades  - cascade ACTION_SAVE_UPDATE for collection: ch.ascom.pasis.common.model.Ibistarget.ibisactions
2906 [main] DEBUG org.hibernate.engine.Cascades  - cascading to saveOrUpdate: ch.ascom.pasis.common.model.Ibisaction
2906 [main] DEBUG org.hibernate.event.def.AbstractSaveEventListener  - persistent instance of: ch.ascom.pasis.common.model.Ibisaction
2906 [main] DEBUG org.hibernate.event.def.DefaultSaveOrUpdateEventListener  - ignoring persistent instance
2906 [main] DEBUG org.hibernate.event.def.DefaultSaveOrUpdateEventListener  - object already associated with session: [ch.ascom.pasis.common.model.Ibisaction#16436]
2906 [main] DEBUG org.hibernate.engine.Cascades  - cascading to saveOrUpdate: ch.ascom.pasis.common.model.Ibisaction
2906 [main] DEBUG org.hibernate.event.def.AbstractSaveEventListener  - persistent instance of: ch.ascom.pasis.common.model.Ibisaction
2906 [main] DEBUG org.hibernate.event.def.DefaultSaveOrUpdateEventListener  - ignoring persistent instance
2906 [main] DEBUG org.hibernate.event.def.DefaultSaveOrUpdateEventListener  - object already associated with session: [ch.ascom.pasis.common.model.Ibisaction#16434]
2906 [main] DEBUG org.hibernate.engine.Cascades  - cascading to saveOrUpdate: ch.ascom.pasis.common.model.Ibisaction
2906 [main] DEBUG org.hibernate.event.def.AbstractSaveEventListener  - persistent instance of: ch.ascom.pasis.common.model.Ibisaction
2906 [main] DEBUG org.hibernate.event.def.DefaultSaveOrUpdateEventListener  - ignoring persistent instance
2906 [main] DEBUG org.hibernate.event.def.DefaultSaveOrUpdateEventListener  - object already associated with session: [ch.ascom.pasis.common.model.Ibisaction#16435]
2906 [main] DEBUG org.hibernate.engine.Cascades  - done cascade ACTION_SAVE_UPDATE for collection: ch.ascom.pasis.common.model.Ibistarget.ibisactions
2906 [main] DEBUG org.hibernate.engine.Cascades  - deleting orphans for collection: ch.ascom.pasis.common.model.Ibistarget.ibisactions
2906 [main] DEBUG org.hibernate.engine.Cascades  - done deleting orphans for collection: ch.ascom.pasis.common.model.Ibistarget.ibisactions
2906 [main] DEBUG org.hibernate.engine.Cascades  - done processing cascade ACTION_SAVE_UPDATE for: ch.ascom.pasis.common.model.Ibistarget
2906 [main] DEBUG org.hibernate.engine.Cascades  - processing cascade ACTION_SAVE_UPDATE for: ch.ascom.pasis.common.model.Ibisaction
2906 [main] DEBUG org.hibernate.engine.Cascades  - done processing cascade ACTION_SAVE_UPDATE for: ch.ascom.pasis.common.model.Ibisaction
2906 [main] DEBUG org.hibernate.engine.Cascades  - processing cascade ACTION_SAVE_UPDATE for: ch.ascom.pasis.common.model.Ibisaction
2906 [main] DEBUG org.hibernate.engine.Cascades  - done processing cascade ACTION_SAVE_UPDATE for: ch.ascom.pasis.common.model.Ibisaction
2906 [main] DEBUG org.hibernate.engine.Cascades  - processing cascade ACTION_SAVE_UPDATE for: ch.ascom.pasis.common.model.Ibisaction
2906 [main] DEBUG org.hibernate.engine.Cascades  - done processing cascade ACTION_SAVE_UPDATE for: ch.ascom.pasis.common.model.Ibisaction
2906 [main] DEBUG org.hibernate.event.def.AbstractFlushingEventListener  - dirty checking collections
2906 [main] DEBUG org.hibernate.event.def.AbstractFlushingEventListener  - Flushing entities and processing referenced collections
2906 [main] DEBUG org.hibernate.engine.Collections  - Collection found: [ch.ascom.pasis.common.model.Ibistarget.ibisactions#16433], was: [ch.ascom.pasis.common.model.Ibistarget.ibisactions#16433] (initialized)
2922 [main] DEBUG org.hibernate.event.def.AbstractFlushingEventListener  - Processing unreferenced collections
2922 [main] DEBUG org.hibernate.event.def.AbstractFlushingEventListener  - Scheduling collection removes/(re)creates/updates
2922 [main] DEBUG org.hibernate.event.def.AbstractFlushingEventListener  - Flushed: 0 insertions, 0 updates, 0 deletions to 4 objects
2922 [main] DEBUG org.hibernate.event.def.AbstractFlushingEventListener  - Flushed: 0 (re)creations, 0 updates, 0 removals to 1 collections
2922 [main] DEBUG org.hibernate.pretty.Printer  - listing entities:
2922 [main] DEBUG org.hibernate.pretty.Printer  - ch.ascom.pasis.common.model.Ibisaction{shortName=Action 1, ibispayload=null, ibisActionId=16435, ibistarget=ch.ascom.pasis.common.model.Ibistarget#16433}
2922 [main] DEBUG org.hibernate.pretty.Printer  - ch.ascom.pasis.common.model.Ibisaction{shortName=Action 2, ibispayload=null, ibisActionId=16434, ibistarget=ch.ascom.pasis.common.model.Ibistarget#16433}
2922 [main] DEBUG org.hibernate.pretty.Printer  - ch.ascom.pasis.common.model.Ibisaction{shortName=Action 3, ibispayload=null, ibisActionId=16436, ibistarget=ch.ascom.pasis.common.model.Ibistarget#16433}
2922 [main] DEBUG org.hibernate.pretty.Printer  - ch.ascom.pasis.common.model.Ibistarget{ibisTargetId=16433, shortName=Target 1, ibisactions=[ch.ascom.pasis.common.model.Ibisaction#16436, ch.ascom.pasis.common.model.Ibisaction#16434, ch.ascom.pasis.common.model.Ibisaction#16435], targetNumber=99}
2922 [main] DEBUG org.hibernate.event.def.AbstractFlushingEventListener  - executing flush
2922 [main] DEBUG org.hibernate.event.def.AbstractFlushingEventListener  - post flush
2922 [main] DEBUG org.hibernate.impl.SessionImpl  - closing session
2922 [main] DEBUG org.hibernate.jdbc.ConnectionManager  - closing JDBC connection [ (open PreparedStatements: 0, globally: 0) (open ResultSets: 0, globally: 0)]
2922 [main] DEBUG org.hibernate.connection.DriverManagerConnectionProvider  - returning connection to pool, pool size: 2
2922 [main] DEBUG org.hibernate.jdbc.JDBCContext  - after transaction completion


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 19, 2006 9:50 am 
Expert
Expert

Joined: Tue Nov 23, 2004 7:00 pm
Posts: 570
Location: mostly Frankfurt Germany
option 1)
A.getBs().remove(B1)
B1.setA(null);
session.remove(B1);

option 2)
cascade="all-delete-orphan"

Regards Sebastian

_________________
Best Regards
Sebastian
---
Training for Hibernate and Java Persistence
Tutorials for Hibernate, Spring, EJB, JSF...
eBook: Hibernate 3 - DeveloperGuide
Paper book: Hibernate 3 - Das Praxisbuch
http://www.laliluna.de


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 20, 2006 4:05 am 
Newbie

Joined: Wed Dec 14, 2005 6:50 am
Posts: 17
Thanx for your reply,

Indeed these are the 2 options i thought of. And as u can see out of the code and mappings, thats exactly what i did.

And for all others out there, who may encounter the same problem, I found the solution after all:
The problem was the native key generator. I'm not yet sure why by now, but if i give away my own keys everything works fine.

For hibernate cracks:
Why interferes the key generator the cascading delete? My generator made always good keys, and the objects are saved and updated well. But with delete there is a problem. It doesn't make any sense to me; By delete a record _no_ key have to be generated!

Thanks,


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 20, 2006 7:15 am 
Newbie

Joined: Wed Dec 14, 2005 6:50 am
Posts: 17
Ok some update here:

I changed the orphan test (provieded by hibernate) to work with the hilo generator, this works fine.
Back in my test, with no id generator everything works. But with the hilo generator, cascading remove still doesn't work. I compeared both mappings, i can't find any difference!
Any brainchild why the cascading would not work with a key generator?

Thanks,


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 23, 2006 12:32 pm 
Newbie

Joined: Wed Dec 14, 2005 6:50 am
Posts: 17
Well, i did find the problem...

My equals method did only use the primarykey for equality. With an other equal method everything works fine.

As can be read in the HIA book (Capture 4.1.6), the identifier approach can't be used with cascade.
But what's the plan, if the pk is the ONLY possbile businesskey? Should i always save a object before adding it to the parents set?

Any help would be appreciated!


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