@Test public void the_audit_continues_silently_if_the_fields_are_missing() { new Audit().setAuditFields(""); }
@PreUpdate @PrePersist public void setAuditFields(Object entity) { final LocalDateTime NOW = now(); for (Field field : entity.getClass().getDeclaredFields()) { if (field.getAnnotation(Auditable.class) != null && field.getType().equals(Date.class)) { try { LOGGER.finest(() -> format("Setting %s field %s to %s", entity.getClass(), field.getName(), NOW)); field.setAccessible(true); field.set(entity, java.sql.Timestamp.valueOf(NOW)); } catch (IllegalAccessException e) { throw new RuntimeException(e); } } } }
Audit { @PreUpdate @PrePersist public void setAuditFields(Object entity) { final LocalDateTime NOW = now(); for (Field field : entity.getClass().getDeclaredFields()) { if (field.getAnnotation(Auditable.class) != null && field.getType().equals(Date.class)) { try { LOGGER.finest(() -> format("Setting %s field %s to %s", entity.getClass(), field.getName(), NOW)); field.setAccessible(true); field.set(entity, java.sql.Timestamp.valueOf(NOW)); } catch (IllegalAccessException e) { throw new RuntimeException(e); } } } } }
Audit { @PreUpdate @PrePersist public void setAuditFields(Object entity) { final LocalDateTime NOW = now(); for (Field field : entity.getClass().getDeclaredFields()) { if (field.getAnnotation(Auditable.class) != null && field.getType().equals(Date.class)) { try { LOGGER.finest(() -> format("Setting %s field %s to %s", entity.getClass(), field.getName(), NOW)); field.setAccessible(true); field.set(entity, java.sql.Timestamp.valueOf(NOW)); } catch (IllegalAccessException e) { throw new RuntimeException(e); } } } }  }
Audit { @PreUpdate @PrePersist public void setAuditFields(Object entity) { final LocalDateTime NOW = now(); for (Field field : entity.getClass().getDeclaredFields()) { if (field.getAnnotation(Auditable.class) != null && field.getType().equals(Date.class)) { try { LOGGER.finest(() -> format("Setting %s field %s to %s", entity.getClass(), field.getName(), NOW)); field.setAccessible(true); field.set(entity, java.sql.Timestamp.valueOf(NOW)); } catch (IllegalAccessException e) { throw new RuntimeException(e); } } } }  @PreUpdate @PrePersist void setAuditFields(Object entity); }
Audit { @PreUpdate @PrePersist public void setAuditFields(Object entity) { final LocalDateTime NOW = now(); for (Field field : entity.getClass().getDeclaredFields()) { if (field.getAnnotation(Auditable.class) != null && field.getType().equals(Date.class)) { try { LOGGER.finest(() -> format("Setting %s field %s to %s", entity.getClass(), field.getName(), NOW)); field.setAccessible(true); field.set(entity, java.sql.Timestamp.valueOf(NOW)); } catch (IllegalAccessException e) { throw new RuntimeException(e); } } } }  @PreUpdate @PrePersist void setAuditFields(Object entity);  }