Skip to content

Commit

Permalink
Merge pull request #460 from RADAR-base/fix/transient-task
Browse files Browse the repository at this point in the history
Fix issue when saving notifications
  • Loading branch information
mpgxvii authored Apr 16, 2024
2 parents caa129b + 68bad69 commit 3c0fa89
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 7 deletions.
3 changes: 2 additions & 1 deletion src/main/java/org/radarbase/appserver/entity/Message.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import org.hibernate.annotations.OnDelete;
import org.hibernate.annotations.OnDeleteAction;
import org.springframework.lang.Nullable;
import jakarta.persistence.CascadeType;

@MappedSuperclass
@Getter
Expand All @@ -64,7 +65,7 @@ public class Message extends AuditModel implements Serializable, Scheduled {
@JsonIgnore
private User user;

@ManyToOne(fetch = FetchType.LAZY, optional = true)
@ManyToOne(fetch = FetchType.LAZY, optional = true, cascade = CascadeType.ALL)
@JoinColumn(name = "task_id", nullable = true)
@OnDelete(action = OnDeleteAction.CASCADE)
@JsonIgnore
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -416,12 +416,11 @@ public List<Notification> addNotifications(List<Notification> notifications,User
notification.getTitle(),
notification.getBody(),
notification.getType(),
notification.getTtlSeconds()).isPresent()
notification.getTtlSeconds()).isEmpty()
)
.collect(Collectors.toList());

List<Notification> savedNotifications = this.notificationRepository.saveAll(newNotifications);
this.notificationRepository.flush();
List<Notification> savedNotifications = this.notificationRepository.saveAllAndFlush(newNotifications);
savedNotifications.forEach(
n -> addNotificationStateEvent(n, MessageState.ADDED, n.getCreatedAt().toInstant()));
this.schedulerService.scheduleMultiple(savedNotifications);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,7 @@ public List<Task> addTasks(List<Task> tasks, User user) {
.filter(task -> !this.taskRepository.existsByUserIdAndNameAndTimestamp(user.getId(), task.getName(), task.getTimestamp()))
.collect(Collectors.toList());

List<Task> saved = this.taskRepository.saveAll(newTasks);
this.taskRepository.flush();

List<Task> saved = this.taskRepository.saveAllAndFlush(newTasks);
saved.forEach(t -> addTaskStateEvent(t, TaskState.ADDED, t.getCreatedAt().toInstant()));

return saved;
Expand Down

0 comments on commit 3c0fa89

Please sign in to comment.