-->
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: Collection vom typ Set wird nicht persistiert
PostPosted: Mon Jul 24, 2006 6:01 am 
Regular
Regular

Joined: Mon May 22, 2006 8:32 am
Posts: 67
Hallo an Alle,

ich habe ein Problem beim Persistieren eines Objektes. Dieses Objekt Rqs verfügt über eine Collection vom Typ Set mit Inhalt RqsDate. In meiner Anwendung gehe ich nun wie folgt vor:
Code:
protected String insertRqs(){
          ...
          Set rqsDates = new HashSet(0);
          Rqs rqs = createRqs();
      
      for (int i = 0; i< countKeys ;i++ ){
         RqsDate rqsdate = createRqsDate(rqs);
         rqsDates.add(rqsdate);
                  
      }
      rqs.setRqsDates(rqsDates);
      
      
      try {
         getRqsHomeInterface().commit(rqs);
      } catch (HibernateException e) {
         // TODO Auto-generated catch block
         e.printStackTrace();
      } catch (SQLException e) {
         // TODO Auto-generated catch block
         e.printStackTrace();
      }
      return null;
   }

private Rqs createRqs(){
      BigDecimal sk =  this.getRqsHomeInterface().getSK();
      
      BigDecimal rqsSk = sk;
      BigDecimal empSk = getUserb().getEmp_sk();
      String src = "WEB";
      String status = "OPEN";
      char chkFlag = 'T';
      char procFlag = 'T';
      BigDecimal procCnt = new BigDecimal("0");
      BigDecimal prty = new BigDecimal("0");
      char notfFlag = 'F';
      BigDecimal creTcsLoginSk = new   BigDecimal("-979999976579");
      Date creTs = new Date();
      BigDecimal seqNum = new BigDecimal("0");
      Date effCreTs = new Date();
      BigDecimal effSeqNum = new BigDecimal("0");
      BigDecimal rank = new BigDecimal("0");
      
      rqs = new Rqs(rqsSk,empSk,src,status,chkFlag,procFlag,procCnt,prty,notfFlag,creTcsLoginSk,creTs,seqNum,effCreTs,effSeqNum,rank);
      
      return rqs;
      
   }
   
private RqsDate createRqsDate(Rqs rqsinst){
      
      BigDecimal sk =  this.rqsHomeInterface.getSK();
      
      BigDecimal rqsDateSk = sk;
      Rqs rqs = rqsinst;
      BigDecimal empSk = getUserb().getEmp_sk();
      
      long days = getActDate();
      
      BigDecimal nomDate =  new BigDecimal(days);
      actDate += 1;
      
      BigDecimal statusNum = new BigDecimal("0");
      
      return new RqsDate(rqsDateSk,rqs,empSk,nomDate,statusNum);
      
   }


Füge ich nur das Objekt Rqs hinzu und kommentiere ich den Code für das Erzeugen von RqsDate aus, wird dieses in die Datenbank übernommen. Erzeuge ich hingegen RqsDates und füge sie dem Set und anschließend dem Objekt Rqs hinzu, so wird das set nicht persistiert.
Debugge ich den Code und schaue ich mir das Objekt Rqs vor dem Persistieren an, so sind alle notwendigen Eigenschaften gesetzt und das Set ist korrekt hinzugefügt.
Beim ausführen der Methode persist() erscheint nur der folgende Hinweis in den Logs:
Code:
Hibernate: /*insert de.businessObjects.Rqs*/insert into TCSDBOWNER.RQS (EMP_SK, SRC, STATUS, CHK_FLAG, PROC_FLAG, PROC_CNT, PRTY, NOTF_FLAG, CRE_TCS_LOGIN_SK, CRE_TS, SEQ_NUM, PROC_START_TS, EFF_CRE_TS, EFF_SEQ_NUM, RANK, RQS_SK) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)

Demnach wurde nur das Objekt Rqs persistent gemacht.

Wo ist mein Fehler? Wo habe ich etwas nicht bedacht? Danke für eure Aufmerksamkeit. Gruß,

ak


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 24, 2006 3:57 pm 
Regular
Regular

Joined: Mon Jun 13, 2005 12:21 pm
Posts: 61
Location: Hannover
Bitte poste doch mal die Mappings dazu.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 25, 2006 2:46 am 
Regular
Regular

Joined: Mon May 22, 2006 8:32 am
Posts: 67
Hi,

mann das habe ich vergesssen! Sorry.
Nu aber:
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated 13.07.2006 10:59:41 by Hibernate Tools 3.1.0.beta5 -->
<hibernate-mapping>
    <class name="de.businessObjects.Rqs" table="RQS" schema="TCSDBOWNER">
        <id name="rqsSk" type="big_decimal">
            <column name="RQS_SK" precision="15" scale="1" />
            <generator class="assigned" />
        </id>
        <property name="empSk" type="big_decimal">
            <column name="EMP_SK" precision="15" scale="1" not-null="true" />
        </property>
        <property name="src" type="string">
            <column name="SRC" length="3" not-null="true" />
        </property>
        <property name="status" type="string">
            <column name="STATUS" length="4" not-null="true" />
        </property>
        <property name="chkFlag" type="char">
            <column name="CHK_FLAG" length="1" not-null="true" />
        </property>
        <property name="procFlag" type="char">
            <column name="PROC_FLAG" length="1" not-null="true" />
        </property>
        <property name="procCnt" type="big_decimal">
            <column name="PROC_CNT" precision="15" scale="1" not-null="true" />
        </property>
        <property name="prty" type="big_decimal">
            <column name="PRTY" precision="15" scale="1" not-null="true" />
        </property>
        <property name="notfFlag" type="char">
            <column name="NOTF_FLAG" length="1" not-null="true" />
        </property>
        <property name="creTcsLoginSk" type="big_decimal">
            <column name="CRE_TCS_LOGIN_SK" precision="15" scale="1" not-null="true" />
        </property>
        <property name="creTs" type="timestamp">
            <column name="CRE_TS" length="7" not-null="true" />
        </property>
        <property name="seqNum" type="big_decimal">
            <column name="SEQ_NUM" precision="15" scale="1" not-null="true" />
        </property>
        <property name="procStartTs" type="timestamp">
            <column name="PROC_START_TS" length="7" />
        </property>
        <property name="effCreTs" type="timestamp">
            <column name="EFF_CRE_TS" length="7" not-null="true" />
        </property>
        <property name="effSeqNum" type="big_decimal">
            <column name="EFF_SEQ_NUM" precision="15" scale="1" not-null="true" />
        </property>
        <property name="rank" type="big_decimal">
            <column name="RANK" precision="15" scale="1" not-null="true" />
        </property>
        <set name="rqsDates" inverse="true">
            <key>
                <column name="RQS_SK" precision="15" scale="1" not-null="true" />
            </key>
            <one-to-many class="de.businessObjects.RqsDate" />
        </set>
    </class>
</hibernate-mapping>


<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated 13.07.2006 10:59:41 by Hibernate Tools 3.1.0.beta5 -->
<hibernate-mapping>
    <class name="de.businessObjects.RqsDate" table="RQS_DATE" schema="TCSDBOWNER">
        <id name="rqsDateSk" type="big_decimal">
            <column name="RQS_DATE_SK" precision="15" scale="1" />
            <generator class="assigned" />
        </id>
        <many-to-one name="rqs" class="de.businessObjects.Rqs" fetch="select">
            <column name="RQS_SK" precision="15" scale="1" not-null="true" />
        </many-to-one>
        <property name="empSk" type="big_decimal">
            <column name="EMP_SK" precision="15" scale="1" not-null="true" />
        </property>
        <property name="nomDate" type="big_decimal">
            <column name="NOM_DATE" precision="15" scale="1" not-null="true" />
        </property>
        <property name="statusNum" type="big_decimal">
            <column name="STATUS_NUM" precision="15" scale="1" not-null="true" />
        </property>
        <set name="rqsDets" inverse="true">
            <key>
                <column name="RQS_DATE_SK" precision="15" scale="1" not-null="true" />
            </key>
            <one-to-many class="de.businessObjects.RqsDet" />
        </set>
    </class>
</hibernate-mapping>


<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated 13.07.2006 10:59:41 by Hibernate Tools 3.1.0.beta5 -->
<hibernate-mapping>
    <class name="de.businessObjects.RqsDet" table="RQS_DET" schema="TCSDBOWNER">
        <id name="rqsDetSk" type="big_decimal">
            <column name="RQS_DET_SK" precision="15" scale="1" />
            <generator class="assigned" />
        </id>
        <many-to-one name="rqsDate" class="de.businessObjects.RqsDate" fetch="select">
            <column name="RQS_DATE_SK" precision="15" scale="1" not-null="true" />
        </many-to-one>
        <property name="actn" type="string">
            <column name="ACTN" length="3" not-null="true" />
        </property>
        <property name="segCodeSk" type="big_decimal">
            <column name="SEG_CODE_SK" precision="15" scale="1" />
        </property>
        <property name="segType" type="string">
            <column name="SEG_TYPE" length="3" />
        </property>
        <property name="detSegSk" type="big_decimal">
            <column name="DET_SEG_SK" precision="15" scale="1" />
        </property>
        <property name="genSegSk" type="big_decimal">
            <column name="GEN_SEG_SK" precision="15" scale="1" />
        </property>
        <property name="startMoment" type="big_decimal">
            <column name="START_MOMENT" precision="15" scale="1" />
        </property>
        <property name="stopMoment" type="big_decimal">
            <column name="STOP_MOMENT" precision="15" scale="1" />
        </property>
        <property name="memo" type="string">
            <column name="MEMO" length="0" />
        </property>
    </class>
</hibernate-mapping>



Was ich noch dazu sagen muss: Die Beziehung RqsDate <=> RqsDet ist im Moment in einem Set abgebildet. Ich benutze aber im Moment eine 1:1 Beziehung. D.h. Zu einem Rqs gehören n RqsDate. Ein RqsDate hat jeweils ein RqsDet.
Ich hoffe das schafft Klarheit? Gruß,

ak


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 25, 2006 8:38 am 
Regular
Regular

Joined: Mon May 22, 2006 8:32 am
Posts: 67
Hallo allerseits,

auch dieses Problem konnte ich in der Zwischenzeit (nach einem Blick in die FAQ) lösen:

[url]
http://www.hibernate.org/116.html#A7
[/url]

Das Problem war das fehlende Attribut cascade="all"

Nun funktioniert es so, wie es angedacht war. Vielen Dank für die Aufmerksamkeit, Gruß,

ak[/quote][/url]


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 25, 2006 12:16 pm 
Regular
Regular

Joined: Mon Jun 13, 2005 12:21 pm
Posts: 61
Location: Hannover
Ok, hatte mir sowas gedacht, deswegen die Nachfrage nach den Mappings. Weiterhin viel Spass mit Hibernate.


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.