Commit 1eaa555e authored by Matija Obreza's avatar Matija Obreza
Browse files

Merge branch 'crud-no-detach' into 'main'

CRUD: Don't detach target entity

See merge request grin-global/grin-global-server!248

(cherry picked from commit 1962dab7)
parent e38b542d
......@@ -144,7 +144,7 @@ public abstract class CRUDServiceImpl<T extends EmptyModel, R extends JpaReposit
@SuppressWarnings("unchecked")
public T update(T updated) {
T target = reload(updated);
entityManager.detach(target);
// entityManager.detach(target);
return (T) Hibernate.unproxy(update(updated, target));
}
......
......@@ -33,6 +33,7 @@ import org.gringlobal.model.AccessionInvName;
import org.gringlobal.model.Inventory;
import org.gringlobal.model.NameGroup;
import org.gringlobal.model.QInventory;
import org.gringlobal.model.TaxonomySpecies;
import org.gringlobal.model.community.CommunityCodeValues;
import org.gringlobal.persistence.AccessionInvNameRepository;
import org.gringlobal.persistence.AccessionRepository;
......@@ -92,7 +93,7 @@ public class AccessionTriggers {
if (!accession.isNew()) {
Accession before = TransactionHelper.executeInTransaction(true, () -> accessionRepository.findById(accession.getId()).orElse(null));
recordAccessionNumberIfNeeded(accession, before);
recordAccessionSpeciesChangesIfNeeded(accession, before);
recordAccessionSpeciesChangesIfNeeded(accession, before.getTaxonomySpecies().getId());
// it's updating, no need to assure systemInventory
Accession updatedAccession = (Accession) joinPoint.proceed();
// rename system inventories after updating
......@@ -187,13 +188,13 @@ public class AccessionTriggers {
accessionInvNameService.create(invName);
}
void recordAccessionSpeciesChangesIfNeeded(Accession accession, Accession before) {
void recordAccessionSpeciesChangesIfNeeded(Accession accession, Long originalTaxonomySpeciesId) {
assert accession.getId() != null;
if (before != null && !Objects.equals(before.getTaxonomySpecies().getId(), accession.getTaxonomySpecies().getId())) {
if (originalTaxonomySpeciesId != null && !Objects.equals(originalTaxonomySpeciesId, accession.getTaxonomySpecies().getId())) {
AccessionInvAnnotation annotation = new AccessionInvAnnotation();
annotation.setAnnotationTypeCode(CommunityCodeValues.ANNOTATION_TYPE_RE_IDENT.value);
annotation.setInventory(inventoryRepository.getSystemInventory(accession));
annotation.setOldTaxonomySpecies(before.getTaxonomySpecies());
annotation.setOldTaxonomySpecies(new TaxonomySpecies(originalTaxonomySpeciesId));
annotation.setNewTaxonomySpecies(accession.getTaxonomySpecies());
annotation.setAnnotationDate(new Date());
annotation.setAnnotationDateCode(CommunityCodeValues.DATE_FORMAT_DATETIME.value);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment