From f4c877103feea8dab16bf7b820f4c38d902c0b6d Mon Sep 17 00:00:00 2001 From: Michael Hirsch Date: Thu, 4 Feb 2016 20:39:29 +0100 Subject: [PATCH 1/2] fix empty in statement of count select when using mysql. Do empty check of list. Signed-off-by: Michael Hirsch --- .../java/org/eclipse/hawkbit/repository/TargetManagement.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/TargetManagement.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/TargetManagement.java index e7483fdd5..75e8c67f3 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/TargetManagement.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/TargetManagement.java @@ -1010,7 +1010,7 @@ public class TargetManagement { @NotNull @PreAuthorize(SpringEvalExpressions.HAS_AUTH_CREATE_TARGET) public List createTargets(@NotNull final List targets) { - if (targetRepository.countByControllerIdIn( + if (!targets.isEmpty() && targetRepository.countByControllerIdIn( targets.stream().map(target -> target.getControllerId()).collect(Collectors.toList())) > 0) { throw new EntityAlreadyExistsException(); } From 7e92f5925e5ef453eb86185d34055882a31fc7bf Mon Sep 17 00:00:00 2001 From: Michael Hirsch Date: Fri, 5 Feb 2016 08:12:12 +0100 Subject: [PATCH 2/2] added flush before executing asynchronous group creation to avoid InvalidDataAccessApiUsageException because Rollout entity has not yet ID set. Signed-off-by: Michael Hirsch --- .../eclipse/hawkbit/repository/RolloutManagement.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/RolloutManagement.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/RolloutManagement.java index 50dc9f2b0..0d3bc62c6 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/RolloutManagement.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/RolloutManagement.java @@ -249,6 +249,14 @@ public class RolloutManagement { final RolloutGroupConditions conditions) { final Rollout savedRollout = createRollout(rollout, amountGroup); creatingRollouts.add(savedRollout.getName()); + // need to flush the entity manager here to get the ID of the rollout, + // because entity manager is set to FlushMode#Auto, entitymanager will + // flush the Target entity, due the indirect relationship to the Rollout + // entity without set an ID JPA is throwing a Invalid + // 'org.springframework.dao.InvalidDataAccessApiUsageException: During + // synchronization aect was found through a relationship that was not + // marked cascade PERSIST' + entityManager.flush(); executor.execute(() -> { try { final DefaultTransactionDefinition def = new DefaultTransactionDefinition(); @@ -336,7 +344,6 @@ public class RolloutManagement { cacheWriteNotify.rolloutGroupCreated(groupIndex, savedRollout.getId(), savedGroup.getId(), amountGroupValidated, groupIndex); pageIndex += groupSize; - } savedRollout.setStatus(RolloutStatus.READY);