-->
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: Lazy loading a map of composite elements
PostPosted: Tue May 03, 2005 3:30 pm 
Beginner
Beginner

Joined: Sun Aug 29, 2004 7:21 pm
Posts: 26
I have a problem with maps of composite elements that don't want to work with lazy loading. I mean they always eagerly load the elements. As here the elements are file attachements, you might imagine this quickely leads to memory issues.

I didn't find anywhere that maps of composite elements couldn't use lazy loading, but still it seams to be the case.
Am I right ?

If I'm wrong, what else could prevent lazy loading from working fine ?

Thanks for the help.

Hibernate version: 3.0.2

Mapping documents:
Code:
<hibernate-mapping>
    <class name="com.windsOfCabarete.infos.ForumPost" table="forum3">
        <id name="unid" column="unid" type="java.lang.String">
            <generator class="uuid.hex"></generator>
        </id>

        <version name="version" column="version" type="int"/>

        <map
            name="attachements"
            table="forum_attachements"
            lazy="true"
            sort="unsorted"
            cascade="all"
        >

            <key column="parent_post_unid"></key>
            <index column="key" type="string"/>

            <composite-element class="com.seanergie.persistence.ImageOrFile">
              <property name="title" type="text" update="true" insert="true" column="title"/>
              <property name="bytes" type="binary" update="true" insert="true" column="bytes"/>
            </composite-element>
        </map>

        <property name="title" type="text" update="true" insert="true" column="title"/>

        other properties here ...
       
    </class>
</hibernate-mapping>


Top
 Profile  
 
 Post subject: Solution found, but may need some work
PostPosted: Wed May 04, 2005 4:03 pm 
Beginner
Beginner

Joined: Sun Aug 29, 2004 7:21 pm
Posts: 26
I've found the problem, and I think it should be resolved in hibernate :

If a super class of a persistant subclass, has a map with public getter & setter, and if the subclasses overloads only the getter, then the map isn't lazy enabled.
Just overloading the setter in the subclass fixes the problem.

I use this configuration because I use XDoclet, and I need only the getter in the subclass to specify the mapping parameters.

Code:
class A{
   protected Map<String,ImageOrFile> attachements;
   /**
     * @hibernate.collection-key column="parent_post_unid"
     * @hibernate.collection-index column="key" type="string"
     * @hibernate.collection-composite-element class="com.seanergie.persistence.ImageOrFile"
     */
   public Map<String,ImageOrFile> getAttachements(){
      return attachements;
   }
   public void setAttachements(Map<String,ImageOrFile> attachements) {
      this.attachements = attachements;
      hasAttachement = attachements != null && !attachements.isEmpty();
   }
}

/**
  * @hibernate.class table="forum3"
*/
class B extends A{
    /**
     * @hibernate.map table="forum_attachements" lazy="true" cascade="all"
     */
   @Override
   public Map<String,ImageOrFile> getAttachements(){
      return attachements;
   }
   // ************ PROBLEM HERE ***********************************
   // the map isn't lazy if this settter isn't overloaded in B
   public void setAttachements(Map<String,ImageOrFile> attachements) {
      super.setAttachements( attachements );
   }
}


I guess the conditions to check if the map can be lazy don't check the super class to see if it has the setter, and so it believes there is no setter, so the map can't be lazy.

Also, with hibernate 2, there used to be some notification at startup when for some reasons lazy loading can't be used. Now, hibernate 3.0.2, goes through this silently. Is there some way to see those warnings ?
It would have saved me a few days of debuging.

Thanks,

Sylvain.

P.S. If nobody objects, I'll add a bug to the JIRA database for this problem.


Top
 Profile  
 
 Post subject: Sorry, I was all wrong
PostPosted: Wed May 04, 2005 4:08 pm 
Beginner
Beginner

Joined: Sun Aug 29, 2004 7:21 pm
Posts: 26
Sorry, the setter in A called map.isEmpty(), and this caused the map to load.

I guess I was all wrong, and hibernate code is fine.


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.