diff --git a/commons/src/main/java/org/eclipse/kapua/commons/model/AbstractKapuaEntity.java b/commons/src/main/java/org/eclipse/kapua/commons/model/AbstractKapuaEntity.java index bb019afc3d3..cfce94f6c00 100644 --- a/commons/src/main/java/org/eclipse/kapua/commons/model/AbstractKapuaEntity.java +++ b/commons/src/main/java/org/eclipse/kapua/commons/model/AbstractKapuaEntity.java @@ -165,7 +165,9 @@ public void setCreatedBy(KapuaId createdBy) { @PrePersist protected void prePersistsAction() { setId(new KapuaEid(IdGenerator.generate())); - setCreatedBy(KapuaSecurityUtils.getSession().getUserId()); + if (KapuaSecurityUtils.getSession() != null) { + setCreatedBy(KapuaSecurityUtils.getSession().getUserId()); + } setCreatedOn(new Date()); } } diff --git a/commons/src/main/java/org/eclipse/kapua/commons/model/AbstractKapuaUpdatableEntity.java b/commons/src/main/java/org/eclipse/kapua/commons/model/AbstractKapuaUpdatableEntity.java index b24fc034de4..fd0febcdf9f 100644 --- a/commons/src/main/java/org/eclipse/kapua/commons/model/AbstractKapuaUpdatableEntity.java +++ b/commons/src/main/java/org/eclipse/kapua/commons/model/AbstractKapuaUpdatableEntity.java @@ -212,7 +212,9 @@ protected void prePersistsAction() { */ @PreUpdate protected void preUpdateAction() { - setModifiedBy(KapuaSecurityUtils.getSession().getUserId()); + if (KapuaSecurityUtils.getSession() != null) { + setModifiedBy(KapuaSecurityUtils.getSession().getUserId()); + } setModifiedOn(new Date()); } }