}
public EntityCollection getChildCollection(String name) throws LayerException {
Type type = metadata.getPropertyType(name);
if (type instanceof CollectionType) {
CollectionType ct = (CollectionType) type;
Collection coll = (Collection) metadata.getPropertyValue(object, name, EntityMode.POJO);
if (coll == null) {
// normally should not happen, hibernate instantiates it automatically
coll = (Collection) ct.instantiate(0);
metadata.setPropertyValue(object, name, coll, EntityMode.POJO);
}
String entityName = ct.getAssociatedEntityName((SessionFactoryImplementor) sessionFactory);
ClassMetadata childMetadata = sessionFactory.getClassMetadata(entityName);
return new HibernateEntityCollection(metadata, childMetadata, object, coll);
} else {
throw new LayerException(ExceptionCode.FEATURE_MODEL_PROBLEM);
}