-->
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: How to retrieve the list-index element in a list collection?
PostPosted: Tue Apr 29, 2008 3:50 pm 
Newbie

Joined: Tue Feb 19, 2008 2:30 pm
Posts: 10
I am using a LIST to map Images to Items. I am using imageid column as my list index element. However the imageid is null when I retrieve Items and their Images. How do should I change the mapping to fix that?

item { itemid, itemname }
image { itemid, imageid, imagetitle }

Please help!

Hibernate version: 3.2

Mapping documents:
Code:
<hibernate-mapping>
   <class name="hello.Item" table="pub.item">
      <id name="id" column="itemid">
         <generator class="sequence">
            <param name="sequence">pub.nextitemidnum</param>
         </generator>
      </id>
      
      <property name="name" column="itemname" />
      
      <list name="images" table="pub.image">
         <key column="itemid" />
         
         <list-index column="imageid" />
         
         <composite-element class="hello.Image">
            <property name="title" column="imagetitle" not-null="true" />
         </composite-element>
      </list>
   </class>
</hibernate-mapping>


Code between sessionFactory.openSession() and session.close():
Code:
      List<Item> items = session.createQuery(
         "from Item i order by i.id desc").list();
      System.out.println(items.size() + " item(s) found:");

      for (Iterator<Item> iter = items.iterator(); iter.hasNext();) {
         Item loadedItem = (Item) iter.next();
         System.out.println("Item #" + loadedItem.getId() + " - " + loadedItem.getName());
         for (int imageNum = 0; imageNum < loadedItem.getImages().size(); imageNum++) {
            Image image = loadedItem.getImages().get(imageNum);
            System.out.println("Item #" + loadedItem.getId() + " - Image #" + image.getId() + " - " + image.getTitle());
         }
      }


Name and version of the database you are using: OpenEdge 10.1B

The generated SQL (show_sql=true):

Hibernate:
Code:
   select
        item0_.itemid as itemid1_,
        item0_.itemname as itemname1_
    from
        pub.item item0_
    order by
        item0_.itemid desc
    1 item(s) found:

Item #11 - 1swyla556em9f

    select
        images0_.itemid as itemid0_,
        images0_.imagetitle as imagetitle0_,
        images0_.imageid as imageid0_
    from
        pub.image images0_
    where
        images0_.itemid=?

Item #11 - Image #null - ut8d6z3emk2d
Item #11 - Image #null - 1eijjsgbv23tz
Item #11 - Image #null - bf52jq6qv400


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.