/** * Generates a new ID value for the given entity instance that is guaranteed * to be unique <i>on this client</i>. If the entity instance with this ID is * ever synchronized to the server, this client-local ID will be replaced by a * permanent server-generated ID. * <p> * This method only works for attributes that are configured as * {@code @GeneratedValue}s. The GenerationType has no effect locally, but of * course it will come into play on the server side when and if the entity is * synchronized to the server. * * @param entityInstance * the entity instance to receive the generated ID. This attribute of * that entity instance will be set to the newly generated ID value. * @return the generated ID value, which has already been set on the entity * instance. */ private <X, T> T generateAndSetLocalId(final X entityInstance, final ErraiSingularAttribute<X, T> attr) { final T nextId = attr.getValueGenerator().next(this); attr.set(entityInstance, nextId); return nextId; }
ErraiSingularAttribute<? super E, Object> idAttr = entityType.getId(Object.class); ErraiIdGenerator<Object> idGenerator = idAttr.getValueGenerator(); if (idGenerator != null && idGenerator.hasNext(desiredStateEm)) { Object newLocalId = idGenerator.next(desiredStateEm); changeId(entityType, conflictingKey.getId(), newLocalId);