Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue when saving notifications #460

Merged
merged 4 commits into from
Apr 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading