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