{
// Populate primary key column
Object rowKey = document.get("_id");
Class<?> rowKeyValueClass = rowKey.getClass();
Class<?> idClass = null;
MetamodelImpl metaModel = (MetamodelImpl) kunderaMetadata.getApplicationMetadata().getMetamodel(
m.getPersistenceUnit());
idClass = m.getIdAttribute().getJavaType();
rowKey = MongoDBUtils.populateValue(rowKey, idClass);
if (metaModel.isEmbeddable(m.getIdAttribute().getBindableJavaType()))
{
EmbeddableType embeddable = metaModel.embeddable(m.getIdAttribute().getBindableJavaType());
Iterator<Attribute> iter = embeddable.getAttributes().iterator();
Object compoundKey = m.getIdAttribute().getBindableJavaType().newInstance();
while (iter.hasNext())
{
AbstractAttribute compositeAttrib = (AbstractAttribute) iter.next();
Object value = ((BasicDBObject) rowKey).get(compositeAttrib.getJPAColumnName());
PropertyAccessorHelper.set(compoundKey, (Field) compositeAttrib.getJavaMember(), value);
}
PropertyAccessorHelper.setId(entity, m, compoundKey);
}
else
{
rowKey = MongoDBUtils.getTranslatedObject(rowKey, rowKeyValueClass, idClass);
PropertyAccessorHelper.setId(entity, m, rowKey);
}
// Populate entity columns
EntityType entityType = metaModel.entity(entityClass);
Set<Attribute> columns = entityType.getAttributes();
for (Attribute column : columns)
{
if (!column.equals(m.getIdAttribute()))
{
String jpaColumnName = ((AbstractAttribute) column).getJPAColumnName();
Class javaType = ((AbstractAttribute) column).getBindableJavaType();
if (metaModel.isEmbeddable(javaType))
{
onViaEmbeddable(column, entity, metaModel, document);
}
else if (!column.isAssociation())
{