I have a number of mapping collection problems when trying to load data from two tables. The table structure is a simple top level table with a referenced list of locations in the second table.
1a. When I try to automatically load from the table using a list (see locationList below) it returns null as the first item in the list. The remaining items are the correct list of locations. So, if I have 3 locations in the table, Hibernate will return 4 entries in the list, with the first being null, and the rest being the correct "Location" type. Why is this?
1b. Using
index column="LOCATION_NBR" lets me specify a sort key, but I want a more complex sort. Is there a way to simply do this?
1c. Is there a reason why I cannot simply specify a database sort (e.g. "order by LOCATION_NBR desc")? This would be much more efficient (due to database indexes) than the Hibernate sort that is currently used. I tried adding a filter and it broke the query.
2. Trying to get around all of these problems, I tried using a set instead (see locationSet below). That makes the null problem go away. However, a Set (by definition) is not guaranteed to have an order. Why then, does it allow me to specify an order-by clause?
Hibernate version: 3.2.0 GA
Mapping documents:
Code:
...
<list name="locationList" table="LOCATION">
<key column="ID"/>
<index column="LOCATION_NBR"/>
<one-to-many class="Location"/>
</list>
Code:
...
<set name="locationSet" order-by="LOCATION_NBR desc">
<key column="ID"/>
<one-to-many class="Location"/>
</set>
Name and version of the database you are using: Oracle 10i