/** * Creates an entity using the given spec, and adds it as a child of this entity. * * @see #addChild(Entity) * @see EntityManager#createEntity(EntitySpec) * * @throws IllegalArgumentException If {@code spec.getParent()} is set and is different from this entity */ @Override public <T extends Entity> T addChild(EntitySpec<T> spec) { if (spec.getParent() != null && !this.equals(spec.getParent())) { throw new IllegalArgumentException("Attempt to create child of "+this+" with entity spec "+spec+ " failed because spec has different parent: "+spec.getParent()); } return addChild(getEntityManager().createEntity(spec)); }