-->
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.  [ 3 posts ] 
Author Message
 Post subject: Problem beim Löschen von Objekten
PostPosted: Sat Nov 17, 2007 6:53 pm 
Newbie

Joined: Wed Jun 20, 2007 1:34 pm
Posts: 1
Hi,
ich bekomme immer folgende Exception:
Quote:
[java] Exception in thread "main" org.hibernate.ObjectDeletedException: deleted object would be re-saved by cascade (remove deleted object from associations): [de.javafalke.jwarehouse.model.Location#10]
[java] at org.hibernate.impl.SessionImpl.forceFlush(SessionImpl.java:1014)
[java] at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:165)
[java] at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.performSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:94)
[java] at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:70)
[java] at org.hibernate.impl.SessionImpl.fireSaveOrUpdate(SessionImpl.java:507)
[java] at org.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:499)
[java] at org.hibernate.engine.CascadingAction$5.cascade(CascadingAction.java:218)
[java] at org.hibernate.engine.Cascade.cascadeToOne(Cascade.java:268)
[java] at org.hibernate.engine.Cascade.cascadeAssociation(Cascade.java:216)
[java] at org.hibernate.engine.Cascade.cascadeProperty(Cascade.java:169)
[java] at org.hibernate.engine.Cascade.cascade(Cascade.java:130)
[java] at org.hibernate.event.def.AbstractFlushingEventListener.cascadeOnFlush(AbstractFlushingEventListener.java:131)
[java] at org.hibernate.event.def.AbstractFlushingEventListener.prepareEntityFlushes(AbstractFlushingEventListener.java:122)
[java] at org.hibernate.event.def.AbstractFlushingEventListener.flushEverythingToExecutions(AbstractFlushingEventListener.java:65)
[java] at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:26)
[java] at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1000)
[java] at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:338)
[java] at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:106)
[java] at de.javafalke.jwarehouse.PersistenceManager.delete(PersistenceManager.java:155)
[java] at de.javafalke.jwarehouse.Run.addSomethingToDB(Run.java:130)
[java] at de.javafalke.jwarehouse.Run.main(Run.java:23)
[java] Java Result: 1


Ich nehm an das ist ein Problem in den Mapping files oder? Also hier mal das hbm.xml zu Location:

Code:
<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE hibernate-mapping PUBLIC
    "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
    "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping>

    <class name="de.javafalke.jwarehouse.model.Location" table="LOCATIONS">

        <id name="id" column="ID_LOCATION">
            <generator class="increment"/>
        </id>

        <property name="name" type="string" column="NAME_LOCATION"/>

      <many-to-one name="parent" cascade="all" class="de.javafalke.jwarehouse.model.Location" column="PARENT_LOCATION"/>
   
      <list name="children" cascade="all" lazy="true">
            <key column="PARENT_LOCATION"/>
            <list-index column="IDX"/>
            <one-to-many class="de.javafalke.jwarehouse.model.Location"/>
       </list>
          
    </class>

</hibernate-mapping>


Oder muss ich doch ganz wo anders suchen?


Top
 Profile  
 
 Post subject: Re: Problem beim Löschen von Objekten
PostPosted: Sun Nov 18, 2007 5:39 pm 
Newbie

Joined: Wed Nov 07, 2007 7:36 pm
Posts: 6
jagdfalke wrote:
<property name="name" type="string" column="NAME_LOCATION"/>

<many-to-one name="parent" cascade="all" class="de.javafalke.jwarehouse.model.Location" column="PARENT_LOCATION"/>

<list name="children" cascade="all" lazy="true">
<key column="PARENT_LOCATION"/>
<list-index column="IDX"/>
<one-to-many class="de.javafalke.jwarehouse.model.Location"/>
</list>


Hallo Jagdfalke,
ich kenne mich mit XML nicht wirklich aus, da ich Annotations benutze, aber 1.) in der Location.hbm.xml kannst Du schlecht als Mapping-Klasse wieder Location angeben.
2.) machen eine Many-To-One und eine Liste auf die gleiche Klasse keinen Sinn.
Hier findest Du wohl eine Lösung:
http://www.hibernate.org/hib_docs/v3/re ... tional-m21
Viele Grüße und viel Erfolg,
Jolliver


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 20, 2007 7:40 am 
Beginner
Beginner

Joined: Thu Jan 04, 2007 5:44 am
Posts: 26
Location: Innsbruck - Sivas(TR) - Bregenz
das delete reicht meistens nicht aus ausser du hast cascadet deleting enabled. Du musst noch bei den assozierenden Objekten das gelöschte Objekt null setzen.. zb du hast ein Person p objekt welche noch eine 1:1 beziehung mit einem Adress a objekt hat und du löschst die adresse mit

session.delete(a);

dann musst du noch

p.setAdresse(null); durchführen.

Bzw. wenn du ein objekt in einer collections löschst evtl mit remove()

sonst versucht hibernate beim commit noch die referenzobjekte die ja in der session gelöscht wurdne wieder zu speichern.


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