-->
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: Lazy attribute behaviour in parent-child relationships
PostPosted: Mon Jan 30, 2006 6:53 am 
Newbie

Joined: Thu Nov 17, 2005 6:35 am
Posts: 7
Hi!


I have a general question regarding the behaviour of lazy attribute settings. I couldn't find an answer to that neither in the Hibernate reference, nor in "Hibernate in Action".

- I have an entity A with a collections of B entities declared as lazy
- The entity B has further sets declared as non-lazy

The problem is that when I select from A without explicitely loading the collection of B entities, the collection is loaded and also the collections of B.

I did expect that the collections of entity B doesn't have to be loaded, because the set of B entities is declared as lazy, but this doesn't seem to be the case.

Do you know the actual behaviour?


Regards,

Matthias


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 30, 2006 12:37 pm 
Newbie

Joined: Wed Dec 14, 2005 6:50 am
Posts: 17
Hi, can you post the mapping files and the code you are executing. It would be mutch easier to help you! Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 30, 2006 4:08 pm 
Newbie

Joined: Thu Nov 17, 2005 6:35 am
Posts: 7
A 'Umfrage' contains a Set of 'fragen', which is lazy.

Code:
<hibernate-mapping package="de.fhzw.portal.umfragesystem.model.domainmodel.umfrage">
   <class name="Umfrage" lazy="true" dynamic-insert="true" dynamic-update="true">
   
      <id name="id" unsaved-value="0">
         <generator class="increment" />
      </id>
   
      <property name="umfrTyp" column="UMFR_TYP" not-null="true" />
      <property name="fragenAufteilung" column="FRAGEN_AUFTEILUNG"
      not-null="true" />
      <property name="bearbZeit" column="BEARB_ZEIT" />
      <property name="fragebogenLayout" column="FRAGEBOGEN_LAYOUT"
      not-null="true" />
    <property name="layoutFile" column="FRAGEBOGEN_LAYOUT_FILE" />   
      <property name="autor" not-null="true" />
    <property name="autorName" column="AUTOR_NAME" />
    <property name="maxSeitenzahl" column="MAX_SEITENZAHL" not-null="true" />
   
      <set name="fragen" lazy="true" inverse="true" cascade="all-delete-orphan">
         <key column="FRAGE_UMFRAGE" />
         <one-to-many class="Frage" />
      </set>

   </class>
</hibernate-mapping>


A Frage contains a Set of 'antworten', which is non-lazy.

Code:
<hibernate-mapping
  package="de.fhzw.portal.umfragesystem.model.domainmodel.umfrage">
   
  <class name="Frage" lazy="true" dynamic-insert="true" dynamic-update="true">
   
      <id name="id" unsaved-value="0">
         <generator class="increment" />
      </id>
   
      <property name="fragetext" />
      <property name="typ" not-null="true" />
      <property name="index" column="FRAGEINDEX" not-null="true" />
      <property name="anmerkfeld" not-null="true" />
    <property name="mussFrage" column="IST_MUSS_FRAGE" not-null="true" />
      <property name="seitenzahl" not-null="true" />
   
      <many-to-one name="umfrage" column="FRAGE_UMFRAGE" class="Umfrage"
      cascade="none" />

      <many-to-one name="zf" column="FRAGE_ZUSGESFRAGE"
         class="Zusammengesetztefrage" cascade="none" />
   
      <set name="antworten" lazy="false" inverse="true"
         cascade="all-delete-orphan">
         <key column="FRAGE_ANTWORT" />
         <one-to-many class="Antwort" />
      </set>
</class>
</hibernate-mapping>


The problem is that the 'fragen' collections and the 'antworten' collections are loaded, although the 'fragen' collection is lazy, and I do not query a 'Frage' or a 'Antwort'.

Is it possible that all that stuff has to be loaded, because the 'antworten' are non-lazy? I thought they would only have to be loaded when the 'fragen' are explicitely loaded.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 30, 2006 4:19 pm 
Newbie

Joined: Thu Nov 17, 2005 6:35 am
Posts: 7
Here's the code that executes the query:

Code:
public List findDfByAutorRoleUmfrTypUmfrZust(Integer uId,
boolean forUmfrSuperManager, Character umfrTyp, Character umfrZust)
throws InfrastructureException {

if (uId == null || umfrTyp == null || umfrZust == null) {
DurchfuehrungDAO.log.error("Null Parameter!");
throw new IllegalArgumentException("Null Parameter!");
}

Session session = HibernateUtil.getUmfrageSession();
Criteria criteria = session.createCriteria(Durchfuehrung.class);
List list = null;

switch (umfrZust.charValue()) {
case UmfrageConstants.NICHT_FREI_CHR:
criteria = criteria.add(Property.forName("freigegeben").eq(
Boolean.FALSE));
break;
case UmfrageConstants.FREI_CHR:
criteria = criteria.add(Property.forName("freigegeben").eq(
Boolean.TRUE));
break;
case UmfrageConstants.NICHT_BEG_CHR:
criteria = criteria.add(Property.forName("umfrBeginn").gt(new Date()));
break;
case UmfrageConstants.BEG_CHR:
criteria = criteria.add(Property.forName("umfrBeginn").lt(new Date()));
break;
case UmfrageConstants.NICHT_BEENDET_CHR:
criteria = criteria.add(Property.forName("umfrEnde").gt(new Date()));
break;
case UmfrageConstants.BEENDET_CHR:
criteria = criteria.add(Property.forName("umfrEnde").lt(new Date()));
break;
case UmfrageConstants.OHNE_ERG_CHR:
criteria = criteria.add(Restrictions.sizeEq("antwortsaetze", 0));
break;
case UmfrageConstants.MIT_ERG_CHR:
criteria = criteria.add(Restrictions.sizeGt("antwortsaetze", 0));
break;
default:
DurchfuehrungDAO.log.debug("Umfragezustand not supported: " + umfrZust);
throw new IllegalArgumentException("umfrZust nicht unterstuetzt!");
}

criteria = criteria.createCriteria("umfrage");

if (forUmfrSuperManager) {
criteria = criteria.add(Property.forName("autor").ne(uId)); // nicht vom Autor
} else {
criteria = criteria.add(Property.forName("autor").eq(uId)); // vom Autor
}

criteria = criteria.add(Property.forName("umfrTyp").eq(umfrTyp));

try {

list = criteria.list();

} catch(HibernateException he) {
throw new InfrastructureException(he);
}
return list;
}



The second case is true. The following mapping file shows the mapping for the entity which is queried in the method and which contains a reference to a 'Umfrage'.

Code:

<hibernate-mapping
  package="de.fhzw.portal.umfragesystem.model.domainmodel.umfrage">
   
  <class name="DfVorlageBasis" table="DF_VORLAGE_BASIS" lazy="true"
    dynamic-insert="true" dynamic-update="true">
   
      <id name="id" unsaved-value="0">
         <generator class="increment" />
      </id>
   
      <property name="bezeichnung" not-null="true" />
      <property name="beschreibung" />
      <property name="begrText" column="BEGR_TEXT" />
      <property name="begrTextAnzeige" column="BEGR_TEXT_ANZEIGE"
      not-null="true" />
    <property name="abschText" column="ABSCH_TEXT" />
      <property name="abschTextAnzeige" column="ABSCH_TEXT_ANZEIGE"
      not-null="true" />
    <property name="teilnSicherheit" column="TEILN_SICHERHEIT"
      not-null="true" />
    <property name="auswSicherheitSuper" column="AUSW_SICHERHEIT_SUPER"
      not-null="true" />
    <property name="auswSicherheitSub" column="AUSW_SICHERHEIT_SUB"
      not-null="true" /> 
      <property name="kennwort" />
      
      <property name="umfrBeginn" type="timestamp" column="UMFR_BEGINN"
      not-null="true" />
      <property name="umfrEnde" type="timestamp" column="UMFR_ENDE"
      not-null="true" />
    <property name="ergPubBeginnOpt" column="ERG_PUB_BEGINN_OPT"
      not-null="true" />   
    <property name="ergPubBeginn" type="timestamp" column="ERG_PUB_BEGINN" />   
    <property name="ergPubEnde" type="timestamp" column="ERG_PUB_ENDE" />
    <property name="ergPubAnzahl" column="ERG_PUB_ANZAHL" />
    <property name="studentenOpt" column="STUDENTEN_OPT" not-null="true" />
    <property name="semester" not-null="true" />
    <property name="stgang" not-null="true" />
    <property name="fach" not-null="true" />
    <property name="gruppe" />
    <property name="dozent" not-null="true" />
    <property name="fachsem" not-null="true" />
    <property name="mitarbeiterOpt" column="MITARBEITER_OPT" not-null="true" />
    <property name="fachbereichStud" column="FACHBEREICH_STUD"
      not-null="true" />
    <property name="fachbereichMit" column="FACHBEREICH_MIT" not-null="true" />
    <property name="bereich" not-null="true" />
   
         
    <many-to-one name="umfrage" class="Umfrage" not-null="true" lazy="false"
      cascade="save-update,persist" />
 
       
   
    <joined-subclass name="Durchfuehrung" lazy="true">
         <key column="ID" />
         <property name="freigegeben" not-null="true" />
      <property name="erneuteDf" column="ERNEUTE_DF" not-null="true" />
      <property name="generiert" not-null="true" />
      <property name="anzahlRegTeilnehmer" column="ANZAHL_REG_TEILNEHMER"
        not-null="true" /> 
      <property name="anzahlErgebnisse" column="ANZAHL_ERGEBNISSE"
        not-null="true" />   
      <set name="antwortsaetze" lazy="true" inverse="true" batch-size="16"
        cascade="all-delete-orphan">
        <key column="DURCHFUEHRUNG" />
        <one-to-many class="Antwortsatz" />
      </set>
      <set name="bereitsabgestimmte" lazy="true" inverse="true"
        cascade="all-delete-orphan">
        <key column="DURCHFUEHRUNG" />
        <one-to-many class="Bereitsabgestimmt" />
      </set>
      <set name="tanbloecke" lazy="true" inverse="true"
        cascade="all-delete-orphan">
        <key column="DURCHFUEHRUNG"/>
        <one-to-many class="Tanblock" />
      </set>
      </joined-subclass>
   
    <joined-subclass name="Vorlage" lazy="true">
         <key column="ID" />
         <property name="gemeinsam" not-null="true" />
      </joined-subclass>
   
   </class>
</hibernate-mapping>


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 01, 2006 4:43 am 
Newbie

Joined: Thu Nov 17, 2005 6:35 am
Posts: 7
Is there anybody who can answer my question...?

Any help would be highly 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.