diff --git a/src/main/java/ee/eesti/riha/rest/dao/ApiGenericDAOImpl.java b/src/main/java/ee/eesti/riha/rest/dao/ApiGenericDAOImpl.java index 6209772..e79d10a 100644 --- a/src/main/java/ee/eesti/riha/rest/dao/ApiGenericDAOImpl.java +++ b/src/main/java/ee/eesti/riha/rest/dao/ApiGenericDAOImpl.java @@ -514,7 +514,7 @@ public int update(T newValue, Integer id) throws RihaRestException { if (JsonContentBasedTable.isJsonContentBasedTable(clazz)) { return updateJsonContentEntity(existing, newValue); } else { - return updateEntity(newValue); + return updateEntity(existing, newValue); } } @@ -554,9 +554,18 @@ private int updateJsonContentEntity(T existing, T newValue) throws RihaRestExcep return 1; } - private int updateEntity(T updatedEntity) { + private int updateEntity(T existing, T updatedEntity) { Session session = sessionFactory.getCurrentSession(); - session.merge(updatedEntity); + + try { + copyNotNullValues(existing, updatedEntity); + session.update(existing); + } catch (IntrospectionException | IllegalAccessException | InvocationTargetException e) { + LOG.error("Failed to update entity {}", existing); + LOG.debug("Failed to update entity", e); + + return 0; + } return 1; } diff --git a/src/main/java/ee/eesti/riha/rest/model/Comment.java b/src/main/java/ee/eesti/riha/rest/model/Comment.java index 0b4404e..29c82a8 100644 --- a/src/main/java/ee/eesti/riha/rest/model/Comment.java +++ b/src/main/java/ee/eesti/riha/rest/model/Comment.java @@ -146,6 +146,7 @@ public Integer getComment_parent_id() { * * @param aComment_parent_id the new comment_parent_id */ + @DisallowUseMethodForUpdate public void setComment_parent_id(Integer aComment_parent_id) { comment_parent_id = aComment_parent_id; } @@ -301,6 +302,7 @@ public String getAuthor_name() { return author_name; } + @DisallowUseMethodForUpdate public void setAuthor_name(String author_name) { this.author_name = author_name; } @@ -309,6 +311,7 @@ public String getAuthor_personal_code() { return author_personal_code; } + @DisallowUseMethodForUpdate public void setAuthor_personal_code(String author_personal_code) { this.author_personal_code = author_personal_code; } @@ -317,6 +320,7 @@ public String getOrganization_name() { return organization_name; } + @DisallowUseMethodForUpdate public void setOrganization_name(String organization_name) { this.organization_name = organization_name; } @@ -325,6 +329,7 @@ public String getOrganization_code() { return organization_code; } + @DisallowUseMethodForUpdate public void setOrganization_code(String organization_code) { this.organization_code = organization_code; } @@ -341,6 +346,7 @@ public String getType() { return type; } + @DisallowUseMethodForUpdate public void setType(String type) { this.type = type; } @@ -349,6 +355,7 @@ public String getSub_type() { return sub_type; } + @DisallowUseMethodForUpdate public void setSub_type(String sub_type) { this.sub_type = sub_type; }