Details
-
Improvement
-
Status: Closed
-
Major
-
Resolution: Fixed
-
None
-
None
Description
Updating a DTO currently still requires custom code in a mapper. This should be reduced to a minimum in the mapper base class.
SimpleQueryInOutMapperBase:
@Inject private QueryInvocationContext context; protected abstract Object getPrimaryKey(Dto dto); protected E findEntity(Object pk) { return (E) context.getEntityManager().find(context.getEntityClass(), pk); } @Override public Object mapParameter(final Object parameter) { Object pk = getPrimaryKey((Dto) parameter); if (pk != null) { E entity = findEntity(pk); return toEntity(entity, (Dto) parameter); } return toEntity(newEntity(), (Dto) parameter); }
Note that this is an API breaking change (toEntity).