From 45a6140ff79daa28f35030578cabbef6609b7922 Mon Sep 17 00:00:00 2001 From: GODrums Date: Tue, 20 Aug 2024 18:17:54 +0200 Subject: [PATCH] fix: transient value error --- .../www1/hephaestus/codereview/CodeReviewService.java | 5 +++-- .../in/www1/hephaestus/codereview/actor/Actor.java | 5 ++--- .../www1/hephaestus/codereview/comment/Comment.java | 5 +++-- .../codereview/comment/CommentConnection.java | 5 +---- .../codereview/pullrequest/Pullrequest.java | 11 ++++++----- .../codereview/pullrequest/PullrequestConnection.java | 5 +---- .../hephaestus/codereview/repository/Repository.java | 3 ++- 7 files changed, 18 insertions(+), 21 deletions(-) diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/CodeReviewService.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/CodeReviewService.java index b2f8959d..6d218095 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/CodeReviewService.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/CodeReviewService.java @@ -49,7 +49,7 @@ public Repository getHephaestusRepository() { example.setName("hephaestus"); example.setNameWithOwner("ls1intum/hephaestus"); Optional foundRepo = codeReviewRepository.findOne(Example.of(example)); - logger.info("All repositories: " + codeReviewRepository.findAll().toString()); + logger.info("Repository count: " + codeReviewRepository.count()); logger.info("Saved repo: " + foundRepo.toString()); if (foundRepo.isPresent()) { @@ -75,7 +75,8 @@ public Repository getHephaestusRepository() { repository.setAddedAt(Instant.now()); System.out.println("Repository: " + repository.toString()); - codeReviewRepository.save(repository); + codeReviewRepository.saveAndFlush(repository); + System.out.println("New Repository count: " + codeReviewRepository.count()); return repository; } diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/actor/Actor.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/actor/Actor.java index 682e652d..34396ab6 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/actor/Actor.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/actor/Actor.java @@ -9,7 +9,6 @@ import de.tum.in.www1.hephaestus.codereview.pullrequest.Pullrequest; import jakarta.persistence.Column; import jakarta.persistence.Entity; -import jakarta.persistence.FetchType; import jakarta.persistence.GeneratedValue; import jakarta.persistence.GenerationType; import jakarta.persistence.OneToMany; @@ -45,12 +44,12 @@ public class Actor { /** * The Pullrequests of the User entity. */ - @OneToMany(mappedBy = "author", fetch = FetchType.LAZY) + @OneToMany(mappedBy = "author") private List pullrequests; /** * The Comments of the User entity. */ - @OneToMany(mappedBy = "author", fetch = FetchType.LAZY) + @OneToMany(mappedBy = "author") private List comments; } diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/comment/Comment.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/comment/Comment.java index c5200141..17fcfa1c 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/comment/Comment.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/comment/Comment.java @@ -10,6 +10,7 @@ import jakarta.persistence.GenerationType; import jakarta.persistence.JoinColumn; import jakarta.persistence.ManyToOne; +import jakarta.persistence.OneToOne; import lombok.Getter; import lombok.Setter; @@ -57,9 +58,9 @@ public class Comment { private Actor author; /** - * The pullrequest of the Comment entity. + * The parent connection to the pullrequest of the Comment entity. */ - @ManyToOne(fetch = FetchType.LAZY) + @OneToOne(optional = false) @JoinColumn(name = "c_connection_id", referencedColumnName = "id") private CommentConnection connection; diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/comment/CommentConnection.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/comment/CommentConnection.java index f7798962..bc926473 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/comment/CommentConnection.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/comment/CommentConnection.java @@ -2,14 +2,11 @@ import java.util.List; -import de.tum.in.www1.hephaestus.codereview.pullrequest.Pullrequest; import jakarta.persistence.Entity; -import jakarta.persistence.FetchType; import jakarta.persistence.GeneratedValue; import jakarta.persistence.GenerationType; import jakarta.persistence.Id; import jakarta.persistence.OneToMany; -import jakarta.persistence.OneToOne; import jakarta.persistence.Table; import lombok.Getter; import lombok.Setter; @@ -23,6 +20,6 @@ public class CommentConnection { @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; - @OneToMany(mappedBy = "connection", fetch = FetchType.LAZY) + @OneToMany(mappedBy = "connection") private List nodes; } diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/Pullrequest.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/Pullrequest.java index fbdf135d..26701001 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/Pullrequest.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/Pullrequest.java @@ -1,12 +1,10 @@ package de.tum.in.www1.hephaestus.codereview.pullrequest; -import java.time.Instant; - import de.tum.in.www1.hephaestus.codereview.actor.Actor; import de.tum.in.www1.hephaestus.codereview.comment.CommentConnection; import jakarta.persistence.Id; import jakarta.persistence.Table; -import jakarta.persistence.Transient; +import jakarta.persistence.CascadeType; import jakarta.persistence.Column; import jakarta.persistence.Entity; import jakarta.persistence.FetchType; @@ -85,11 +83,14 @@ public class Pullrequest { /** * The comments of the Pullrequest entity. */ - @OneToOne(optional = false) + @OneToOne(cascade = CascadeType.ALL, optional = false) @JoinColumn(name = "c_connection_id", referencedColumnName = "id") private CommentConnection comments; - @ManyToOne(fetch = FetchType.LAZY) + /** + * The parent connection of the Pullrequest entity. + */ + @OneToOne(optional = false) @JoinColumn(name = "pr_connection_id", referencedColumnName = "id") private PullrequestConnection connection; } diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/PullrequestConnection.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/PullrequestConnection.java index 2b3800c0..29a89128 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/PullrequestConnection.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/pullrequest/PullrequestConnection.java @@ -2,13 +2,10 @@ import java.util.List; -import de.tum.in.www1.hephaestus.codereview.repository.Repository; import jakarta.persistence.Id; import jakarta.persistence.OneToMany; -import jakarta.persistence.OneToOne; import jakarta.persistence.Table; import jakarta.persistence.Entity; -import jakarta.persistence.FetchType; import jakarta.persistence.GeneratedValue; import jakarta.persistence.GenerationType; import lombok.Getter; @@ -23,6 +20,6 @@ public class PullrequestConnection { @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; - @OneToMany(mappedBy = "connection", fetch = FetchType.LAZY) + @OneToMany(mappedBy = "connection") private List nodes; } diff --git a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/repository/Repository.java b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/repository/Repository.java index 87f69cf3..c597988f 100644 --- a/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/repository/Repository.java +++ b/server/application-server/src/main/java/de/tum/in/www1/hephaestus/codereview/repository/Repository.java @@ -3,6 +3,7 @@ import java.time.Instant; import de.tum.in.www1.hephaestus.codereview.pullrequest.PullrequestConnection; +import jakarta.persistence.CascadeType; import jakarta.persistence.Column; import jakarta.persistence.Entity; import jakarta.persistence.GeneratedValue; @@ -42,7 +43,7 @@ public class Repository { @Column private String url; - @OneToOne(optional = false) + @OneToOne(cascade = CascadeType.ALL, optional = false) @JoinColumn(name = "connection_id", referencedColumnName = "id") private PullrequestConnection pullRequests;