public void load(final OpenJPAStateManager sm, final JDBCStore store,
final JDBCFetchConfiguration fetch)
throws SQLException {
if (field.isLRS()) {
Proxy coll = newLRSProxy();
// if this is ordered we need to know the next seq to use in case
// objects are added to the collection
if (field.getOrderColumn() != null) {
// we don't allow ordering table per class one-many's, so
// we know we don't need a union
Select sel = store.getSQLFactory().newSelect();
sel.setAggregate(true);
StringBuffer sql = new StringBuffer();
sql.append("MAX(").
append(sel.getColumnAlias(field.getOrderColumn())).
append(")");
sel.select(sql.toString(), field);
ClassMapping rel = getDefaultElementMapping(false);
sel.whereForeignKey(getJoinForeignKey(rel),
sm.getObjectId(), field.getDefiningMapping(), store);
Result res = sel.execute(store, fetch);
try {
res.next();
coll.getChangeTracker().setNextSequence
(res.getInt(field) + 1);
} finally {
res.close();
}
}