-
Notifications
You must be signed in to change notification settings - Fork 75
Open
Description
Estou fazendo uns testes com demoiselle 3. Notei que o método mergeHalf (baseado em PATCH) do AbstractDAO parece incompleto e errado.
- ta invocando TUDO, os gets (o que é correto) e os sets tb (o que é errado)
- linha 76, ta passando erradamente a classe
entityClassao invés da instânciaentity
Abaixo segue uma implementação sugerida que vai direto no field com mapped column...
try {
StringBuilder sb = new StringBuilder();
sb.append("UPDATE ");
sb.append(entity.getClass().getCanonicalName());
sb.append(" SET ");
for (Field method : entity.getClass().getDeclaredFields()) {
method.setAccessible(true);
if (method.isAnnotationPresent(Column.class)) {
Object obj = method.get(entity);
if (obj != null) {
sb.append(method.getName()).append(" = ").append(obj).append(",");
}
}
}
if (sb.toString().endsWith(",")) {
int i = sb.lastIndexOf(",");
sb.delete(i, i + 1);
// TODO ainda falta testar chaves multiplas com @EmbeddedId
sb.append(" WHERE ").append(CrudUtilHelper.getMethodAnnotatedWithID(entity.getClass())).append(" = ")
.append(id);
getEntityManager().createQuery(sb.toString()).executeUpdate();
}
return entity;
} catch (Exception e) {
throw new DemoiselleCrudException("Não foi possível salvar", e);
}Att. Emanuel Motta Grohs
[UPDATE - Merlin]: apenas formatei o código pra ficar mais amigável ;)
Metadata
Metadata
Assignees
Labels
No labels