private void setMappedBy(Object oid, OpenJPAStateManager sm, Object coll,
Result res) {
// for inverseEager field
FieldMapping mappedByFieldMapping = field.getMappedByMapping();
PersistenceCapable mappedByValue = null;
if (mappedByFieldMapping != null) {
ValueMapping val = mappedByFieldMapping.getValueMapping();
ClassMetaData decMeta = val.getTypeMetaData();
// this inverse field does not have corresponding classMapping
// its value may be a collection/map etc.
if (decMeta == null)
return;
StateManagerImpl owner = ((StateManagerImpl)sm).getObjectIdOwner();
if (oid.equals(owner.getObjectId())) {
mappedByValue = owner.getPersistenceCapable();
res.setMappedByFieldMapping(mappedByFieldMapping);
res.setMappedByValue(mappedByValue);
} else if (coll instanceof Collection &&
((Collection) coll).size() > 0) {
// Customer (1) <--> Orders(n)
// coll contains the values of the toMany field (Orders)
// get the StateManager of this toMany value
// and find the value of the inverse mappedBy field (Customer)
// for this toMacdny field
PersistenceCapable pc = (PersistenceCapable)
((Collection) coll).iterator().next();
OpenJPAStateManager sm1 = (OpenJPAStateManager) pc.
pcGetStateManager();
ClassMapping clm = ((ClassMapping) sm1.getMetaData());
FieldMapping fm = (FieldMapping) clm.getField(
mappedByFieldMapping.getName());