-->
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.  [ 2 posts ] 
Author Message
 Post subject: "where" in set-mapping prevents lazy loading ?
PostPosted: Thu Dec 08, 2005 10:12 am 
Newbie

Joined: Thu Dec 08, 2005 9:57 am
Posts: 3
We have the problem, that when we restrict the one side of a
many-to-one association with a 'where' attribute, lazy loading is
switched off always.

The mapping we are using looks like

Code:
  <class
      name="Board"
      table="t_board"
      dynamic-update="true"
      dynamic-insert="true"
      >
    <!--  ......  -->
    <list
        name="standardTopics"
        lazy="true"
        inverse="false"
        where="category = 'S'"
        >
     
      <key column="board_id"/>
      <list-index column="board_index"/>
      <one-to-many class="BoardTopic"/>
    </list>

    <set
        name="pooledTopics"
        lazy="true"
        inverse="true"
        where="category = 'V'"
        >

      <key column="board_id"/>
      <one-to-many class="BoardTopic"/>
    </set>
  </class>   


When using a simple Session.get() on the Board class, the following
SQL statements are executed:

Code:
    [java] 5649     DEBUG        hibernate.SQL|
select ...
from t_topic standardto0_
where standardto0_.category = 'S' and standardto0_.board_id=?

     [java] 5680     DEBUG        hibernate.SQL|
select ...
from t_topic pooledtopi0_
where pooledtopi0_.category = 'V' and pooledtopi0_.board_id=?

     [java] 5691     DEBUG        hibernate.SQL|
select ...
from t_topic requestedt0_
where requestedt0_.board_id=?


Otherwise, when the 'where' is removed from the mapping, then lazy loading works as expected (e.g. only the first select is executed).

Is this a Bug, Limitations, Feature or maybe a wrong mapping ?

...roland

Hibernate version: 3.1RC3


Top
 Profile  
 
 Post subject:
PostPosted: Sat Dec 10, 2005 3:16 am 
Newbie

Joined: Thu Dec 08, 2005 9:57 am
Posts: 3
Forget about the previous posting, the error wasn't the 'where' clause
but a stupid programming error on my side:

I used a setter method like

Code:
    public void setRequestedTopics(Set requestedTopics) {
        if (requestedTopics != null) {
            for (Iterator iterator = requestedTopics.iterator(); iterator.hasNext();) {
                BoardTopic topic = (BoardTopic) iterator.next();
                Assert.isTrue(topic.getBoardTopicCategory() == BoardTopicCategory.REQUEST,
                        "Internal: Only topics of type " + BoardTopicCategory.REQUEST.getName() + " are allowed");
            }
            this.requestedTopics = requestedTopics;
        }
    }


The iteration of the given proxy collection in the argument (in case of lazy loading) of course triggers initialization of the collection in any case.

BTW, does anybody know a better way for validating the elements of
a collection ?


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