diff --git a/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsUnixUserHostingAssetValidator.java b/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsUnixUserHostingAssetValidator.java index 9f2ac336..024866c2 100644 --- a/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsUnixUserHostingAssetValidator.java +++ b/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsUnixUserHostingAssetValidator.java @@ -6,7 +6,6 @@ import net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetType; import net.hostsharing.hsadminng.hs.validation.PropertiesProvider; import jakarta.persistence.EntityManager; -import jakarta.persistence.FlushModeType; import java.util.regex.Pattern; import static net.hostsharing.hsadminng.hs.validation.BooleanProperty.booleanProperty; @@ -54,7 +53,6 @@ class HsUnixUserHostingAssetValidator extends HostingAssetEntityValidator { } private static Integer computeUserId(final EntityManager em, final PropertiesProvider propertiesProvider) { - em.setFlushMode(FlushModeType.COMMIT); // FIXME: check and remove or reset final Object result = em.createNativeQuery("SELECT nextval('hs_hosting.asset_unixuser_system_id_seq')", Integer.class) .getSingleResult(); return (Integer) result; diff --git a/src/main/java/net/hostsharing/hsadminng/hs/office/debitor/HsOfficeDebitorController.java b/src/main/java/net/hostsharing/hsadminng/hs/office/debitor/HsOfficeDebitorController.java index ee8909c3..0ac686ee 100644 --- a/src/main/java/net/hostsharing/hsadminng/hs/office/debitor/HsOfficeDebitorController.java +++ b/src/main/java/net/hostsharing/hsadminng/hs/office/debitor/HsOfficeDebitorController.java @@ -106,9 +106,7 @@ public class HsOfficeDebitorController implements HsOfficeDebitorsApi { final var entityToSave = mapper.map(body, HsOfficeDebitorEntity.class, RESOURCE_TO_ENTITY_POSTMAPPER); - final var savedEntity = debitorRepo.save(entityToSave).load(); -// em.flush(); // FIXME: necessary? -// em.refresh(savedEntity); + final var savedEntity = debitorRepo.save(entityToSave).reload(em); final var uri = MvcUriComponentsBuilder.fromController(getClass()) diff --git a/src/main/java/net/hostsharing/hsadminng/persistence/BaseEntity.java b/src/main/java/net/hostsharing/hsadminng/persistence/BaseEntity.java index b3e5a535..aede0d7d 100644 --- a/src/main/java/net/hostsharing/hsadminng/persistence/BaseEntity.java +++ b/src/main/java/net/hostsharing/hsadminng/persistence/BaseEntity.java @@ -3,6 +3,7 @@ package net.hostsharing.hsadminng.persistence; import org.hibernate.Hibernate; +import jakarta.persistence.EntityManager; import java.util.UUID; public interface BaseEntity> { @@ -15,4 +16,10 @@ public interface BaseEntity> { //noinspection unchecked return (T) this; }; + + default T reload(final EntityManager em) { + em.flush(); + em.refresh(this); + return load(); + } }