//fetch group does not work with partial attribute reading
throw QueryException.fetchGroupNotSupportOnPartialAttributeReading();
}
}
Set attributes = query.getFetchGroup().getAttributes();
ObjectBuilder builder = query.getDescriptor().getObjectBuilder();
//First add all primary key attributes into the fetch group
Iterator pkMappingIter = builder.getPrimaryKeyMappings().iterator();
while (pkMappingIter.hasNext()) {
DatabaseMapping pkMapping = (DatabaseMapping)pkMappingIter.next();
DatabaseField pkField = pkMapping.getField();
// Add pk attribute to the fetch group attributes list
attributes.add(pkMapping.getAttributeName());
}
//second, add version/optimistic locking object attributes into the fetch group if applied.
OptimisticLockingPolicy lockingPolicy = getDescriptor().getOptimisticLockingPolicy();
if (query.shouldMaintainCache() && (lockingPolicy != null)) {
lockingPolicy.prepareFetchGroupForReadQuery(query.getFetchGroup(), query);
}
//thrid, prepare all fetch group attributes
Iterator attrIter = attributes.iterator();
while (attrIter.hasNext()) {
String attrName = (String)attrIter.next();
DatabaseMapping mapping = builder.getMappingForAttributeName(attrName);
if (mapping == null) {
//the attribute name defined in the fetch group is not mapped
throw QueryException.fetchGroupAttributeNotMapped(attrName);
}