/** * Tries to obtain or create an associated entity. Note that if #canExpandMappingContext is set to false then this method may return null * * @param entity The main entity * @param context The context * @param propType The associated property type * @return The associated entity or null */ protected PersistentEntity getOrCreateAssociatedEntity(PersistentEntity entity, MappingContext context, Class propType) { PersistentEntity associatedEntity = context.getPersistentEntity(propType.getName()); if (associatedEntity == null) { if(canExpandMappingContext) { if (entity.isExternal()) { associatedEntity = context.addExternalPersistentEntity(propType); } else { associatedEntity = context.addPersistentEntity(propType); } } } else { if(!associatedEntity.isInitialized()) { associatedEntity.initialize(); } } return associatedEntity; }
associatedEntity = context.addExternalPersistentEntity(type); associatedEntity.initialize();