-->
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.  [ 1 post ] 
Author Message
 Post subject: accessing a lazy loaded attribute from the POJO
PostPosted: Wed Jun 21, 2006 6:09 am 
Newbie

Joined: Wed Jun 21, 2006 5:36 am
Posts: 1
Location: Paris
Hibernate version: 3.1.2

Mapping documents:
Code:
<list name="movieRolePerson" table="movie_roleperson">
         <cache usage="read-write" />
            <key column="movieid"/>
            <index column="index"/>
            <composite-element class="FilmRolePerson">
               <parent name="movie"/>
               <property name="role" column="role" type="string"/>
               <many-to-one name="person" class="Person"
                  column="personid" fetch="select"/>
            </composite-element>
        </list>


This is a classic n-n join table with attributes.
For examples : Robert work for a movie A as an actor, and he work for a movie B as an executive producer.

Now for a movie, i wont all the actors, or i wont to iter on every role and every person.

Code:
public Map<Role,List<Person>> getAllPerson() {
   Map<Role,List<Person>> map = new HashMap<Role,List<Person>>();
   Iterator<MovieRolePerson> iter = this.getMovieRolePerson().iterator();
   MovieRolePerson frp;
   while(iter.hasNext()){
      frp = iter.next();
      if(! map.containsKey(frp.getRole())){
         map.put(frp.getRole(), new ArrayList<Person>());
      }
      map.get(frp.getRole()).add(frp.getPerson());
   }
   return map;
}


It works very nice if i don't use lazy loading, and I think it's better for the database than first asking for distinct role, and after asking for person with that role. The problem is the lazy loading. The lazy stuff is done in a proxy, with cglib, but my method is in the proxy, it can't proxied getter, so the
Code:
this.getMovieRolePerson()
return an empty list.
The doc talk about proxy generation :Tuplizers but don't say how, there's a big TODO for later.

Is it stupid to do the work in the POJO, is it better to use nice HQL query in the DAO with explicit join? Is it easy to explain to the proxi that I wont to fetch this lazy list?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.