Description
We have an object mapping defined that contains a collection-descriptor. That collection-descriptor uses an orderby attribute and an indirection table, as follows:
<class-descriptor class="com.dchoc.common.entity.LeagueEntity" table="LEAGUES">
<field-descriptor id="1" name="id" column="ID" jdbc-type="INTEGER" primarykey="true" autoincrement="true"/>
<field-descriptor id="2" name="name" column="NAME" jdbc-type="VARCHAR"/>
<collection-descriptor
name="members"
auto-retrieve="true"
auto-update="object"
auto-delete="object"
proxy="true"
indirection-table="LEAGUE_MEMBERS"
orderby="leagueSequence"
element-class-ref="com.dchoc.common.entity.LeagueAccountEntity">
<fk-pointing-to-this-class column="LEAGUE_ID"/>
<fk-pointing-to-element-class column="LEAGUE_ACCOUNT_ID"/>
</collection-descriptor>
</class-descriptor>
We were having problems where sometimes the objects returned in the members collection were ordered by the leagueSequence, and sometimes they weren't. From our testing, we determined that the objects in the members collection were ordered by leagueSequence when the LeagueEntity objects were obtained via a call to PersistenceBroker.getObjectByQuery(Query). When the LeagueEntity objects were obtained via a call to PersistenceBroker.getCollectionByQuery(Query), the objects in the members collection were not ordered by leagueSequence (they were ordered by a default order of ID/primary key). We turned on the SQL generation for OJB and verified that in the former case, the SQL select statement includes an order by clause, and in the latter case, it does not.