Class clazz = entity.getClass();
String id = getIdFieldName(clazz);
Map<String, Object> properties = getEntityProperties(entity);
DynamicType type = getDynamicEntityType(clazz);
if (type != null) {
dynamicEntity = em.find(type.getJavaClass(), properties.get(id));
boolean create = dynamicEntity == null;
if (create) {
dynamicEntity = type.newDynamicEntity();
}
// has this entity already been accounted for?
if (persistSet.contains(dynamicEntity)) {
return dynamicEntity;
}
persistSet.add(dynamicEntity);
for (String propertyName : type.getPropertiesNames()) {
if (properties.containsKey(propertyName)) {
Object value = properties.get(propertyName);
if (value != null) {
Class<?> valueClass = value.getClass();