protected void loadEntityId(Element element, InstanceLoader<Entity> loader) { String entityIdStr = element.attributeValue("entityId"); if (Strings.isNullOrEmpty(entityIdStr)) { return; } MetaProperty property = metadataTools.getPrimaryKeyProperty(loader.getContainer().getEntityMetaClass()); if (property == null) { throw new IllegalStateException("Cannot determine id property for " + loader.getContainer().getEntityMetaClass()); } if (property.getRange().isDatatype()) { try { Object value = property.getRange().asDatatype().parse(entityIdStr); loader.setEntityId(value); } catch (ParseException e) { throw new RuntimeException("Error parsing entityId for " + loader, e); } } else { throw new IllegalStateException("Cannot assign id to " + loader + " because the entity has a composite PK"); } }