-->
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: update a POJO with an list, where one element on List is del
PostPosted: Wed Oct 06, 2004 2:43 am 
Newbie

Joined: Wed Jun 02, 2004 6:14 am
Posts: 6
HI,
I have a problem with update my persistence Object. In the Object is a
list with REF_PROJEKT_ENTITY-Objects. When I change values in same REF_PROJEKT_ENTITY-Objects or take a new
to the list, the update will work fine and I can see the canges in the database. But if I remove one REF_PROJEKT_ENTITY-object from
the list, the value are not delete in the
database?
What is wrong?
Claudia

Hibernate version: 2

Mapping documents:
Code:
<class name="Projekt" table="DATA_PROJEKT">
      <id name="projekt_id"  type="java.lang.Long">
                        <column name="PROJEKT_ID" sql-type="number" not-null="true" />
         <generator class="sequence">
                            <param name="sequence">SEQ_DATA_PROJEKT</param>
                        </generator>
      </id>
      <property name="name" type="string">
                    <column name="NAME" sql-type="VARCHAR(100)" />
                </property>
                <property name="info" type="string">
                    <column name="INFO" sql-type="VARCHAR(100)" />
                </property>
                <list name="projektDDE" table="REF_PROJEKT_ENTITY" inverse="true" cascade="all">
                    <key column="projekt_id"/>
                    <index column="projekt_entity_id"/>
                    <one-to-many class="RefProjektEntity"  />
                </list>
          </class>


Code between sessionFactory.openSession() and session.close():
Code:
Transaction tx=null;
session =this.getSession();
tx=session.beginTransaction();
           
Projekt p=buchung.getProkekt();

session.saveOrUpdate(p);
session.flush();
           
tx.commit();



Name and version of the database you are using:Oracle 8

The generated SQL (show_sql=true):
[code]Hibernate: select this.PROJEKT_ID as PROJEKT_ID0_, this.NAME as NAME0_, this.INFO as INFO0_, this.OWNER_USER_ID as OWNER_US4_0_, this.LASTUPDATE as LASTUPDATE0_ from DATA_PROJEKT this where this.PROJEKT_ID=?
Hibernate: select projektdde0_.PROJEKT_ENTITY_ID as PROJEKT_1___, projektdde0_.projekt_id as projekt_id__, projektdde0_.projekt_entity_id as projekt_8___, projektdde0_.PROJEKT_ENTITY_ID as PROJEKT_1_1_, projektdde0_.INFO as INFO1_, projektdde0_.VARIANTE as VARIANTE1_, projektdde0_.entity_id as entity_id1_, projektdde0_.Projekt_ID as Projekt_ID1_, projektdde0_.LASTUPDATE as LASTUPDATE1_, entity1_.ENTITY_ID as ENTITY_ID0_, entity1_.BESCHREIBUNG as BESCHREI2_0_, entity1_.DDE as DDE0_, entity1_.NAME as NAME0_, entity1_.JAHR as JAHR0_ from REF_PROJEKT_ENTITY projektdde0_, kat_entity entity1_ where projektdde0_.projekt_id=? and projektdde0_.entity_id=entity1_.ENTITY_ID(+)
Hibernate: select items0_.JAHR as JAHR__, items0_.item_id as item_id__, items0_.art_id as art_id__, items0_.entity_id as entity_id__, items0_.ref_entity_item_id as ref_enti5___, item1_.ITEM_ID as ITEM_ID0_, item1_.DDI as DDI0_, item1_.NAME as NAME0_, item1_.L


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 06, 2004 8:27 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
Removing an entity from the collectio of another entity will not delete that first entity from the database by default. It simply "unassociates" the two by updating the FK. If you want this behaviour, you need to change your cascade style from "all" to "all-delete-orphan"


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 06, 2004 9:22 am 
Newbie

Joined: Wed Jun 02, 2004 6:14 am
Posts: 6
Thanks,

but when I change casade fom all to all-delete-orphan
the following exception is thrown:

net.sf.hibernate.HibernateException: You may not dereference a collection with cascade="all-delete-orphan"
at net.sf.hibernate.impl.SessionImpl.updateUnreachableCollection(SessionImpl.java:2910)
at net.sf.hibernate.impl.SessionImpl.flushCollections(SessionImpl.java:2779)
at net.sf.hibernate.impl.SessionImpl.flushEverything(SessionImpl.java:2250)
at net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2228)
at net.sf.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:61)

claudia


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.