From b4a5bfd4b7cc3ac888ae37a973c38aaef0f0af97 Mon Sep 17 00:00:00 2001 From: Matthias Andreas Benkard Date: Sun, 6 Aug 2023 21:57:45 +0200 Subject: More Hibernate 6.2 compatibility. Change-Id: Ib06822de4e2d64419a8285c0a46b2d8931cea4c8 --- src/main/java/eu/mulk/mulkcms2/benki/bookmarks/Bookmark.java | 2 ++ .../java/eu/mulk/mulkcms2/benki/bookmarks/BookmarkResource.java | 9 +++++---- .../java/eu/mulk/mulkcms2/benki/lazychat/LazychatMessage.java | 1 + .../java/eu/mulk/mulkcms2/benki/lazychat/LazychatResource.java | 6 +++--- src/main/java/eu/mulk/mulkcms2/benki/posts/PostResource.java | 4 +++- src/main/java/eu/mulk/mulkcms2/benki/posts/PostText.java | 6 ++++-- src/main/java/eu/mulk/mulkcms2/benki/posts/PostTextPK.java | 6 +++--- 7 files changed, 21 insertions(+), 13 deletions(-) (limited to 'src/main/java') diff --git a/src/main/java/eu/mulk/mulkcms2/benki/bookmarks/Bookmark.java b/src/main/java/eu/mulk/mulkcms2/benki/bookmarks/Bookmark.java index 01e8a99..25fe683 100644 --- a/src/main/java/eu/mulk/mulkcms2/benki/bookmarks/Bookmark.java +++ b/src/main/java/eu/mulk/mulkcms2/benki/bookmarks/Bookmark.java @@ -60,6 +60,7 @@ public class Bookmark extends Post { if (text == null) { text = new BookmarkText(); text.post = this; + text.postId = id; text.language = ""; texts.put(text.language, text); } @@ -72,6 +73,7 @@ public class Bookmark extends Post { if (text == null) { text = new BookmarkText(); text.post = this; + text.postId = id; text.language = ""; texts.put(text.language, text); } diff --git a/src/main/java/eu/mulk/mulkcms2/benki/bookmarks/BookmarkResource.java b/src/main/java/eu/mulk/mulkcms2/benki/bookmarks/BookmarkResource.java index c9304b5..4d08298 100644 --- a/src/main/java/eu/mulk/mulkcms2/benki/bookmarks/BookmarkResource.java +++ b/src/main/java/eu/mulk/mulkcms2/benki/bookmarks/BookmarkResource.java @@ -68,14 +68,15 @@ public class BookmarkResource extends PostResource { var bookmark = new Bookmark(); bookmark.uri = uri.toString(); bookmark.tags = Set.of(); - bookmark.setTitle(title); - bookmark.setDescription(description); bookmark.owner = user; bookmark.date = OffsetDateTime.now(); - assignPostTargets(visibility, user, bookmark); + bookmark.persist(); - bookmark.persistAndFlush(); + bookmark.setTitle(title); + bookmark.setDescription(description); + + assignPostTargets(visibility, user, bookmark); return Response.seeOther(new URI("/bookmarks")).build(); } diff --git a/src/main/java/eu/mulk/mulkcms2/benki/lazychat/LazychatMessage.java b/src/main/java/eu/mulk/mulkcms2/benki/lazychat/LazychatMessage.java index 9181adf..40788d5 100644 --- a/src/main/java/eu/mulk/mulkcms2/benki/lazychat/LazychatMessage.java +++ b/src/main/java/eu/mulk/mulkcms2/benki/lazychat/LazychatMessage.java @@ -50,6 +50,7 @@ public class LazychatMessage extends Post { if (text == null) { text = new LazychatMessageText(); text.post = this; + text.postId = id; text.language = ""; texts.put(text.language, text); } diff --git a/src/main/java/eu/mulk/mulkcms2/benki/lazychat/LazychatResource.java b/src/main/java/eu/mulk/mulkcms2/benki/lazychat/LazychatResource.java index 4a36cf8..e93f7de 100644 --- a/src/main/java/eu/mulk/mulkcms2/benki/lazychat/LazychatResource.java +++ b/src/main/java/eu/mulk/mulkcms2/benki/lazychat/LazychatResource.java @@ -45,13 +45,13 @@ public class LazychatResource extends PostResource { var user = Objects.requireNonNull(getCurrentUser()); var message = new LazychatMessage(); - message.setContent(text); message.owner = user; message.date = OffsetDateTime.now(); - assignPostTargets(visibility, user, message); + message.persist(); + message.setContent(text); - message.persistAndFlush(); + assignPostTargets(visibility, user, message); return Response.seeOther(new URI("/lazychat")).build(); } diff --git a/src/main/java/eu/mulk/mulkcms2/benki/posts/PostResource.java b/src/main/java/eu/mulk/mulkcms2/benki/posts/PostResource.java index db613ae..0be31d7 100644 --- a/src/main/java/eu/mulk/mulkcms2/benki/posts/PostResource.java +++ b/src/main/java/eu/mulk/mulkcms2/benki/posts/PostResource.java @@ -325,9 +325,11 @@ public abstract class PostResource { comment.date = OffsetDateTime.now(); comment.scope = Scope.comment; comment.referees = List.of(post); + + comment.persist(); + comment.setContent(message); assignPostTargets(post.getVisibility(), post.owner, comment); - comment.persist(); var currentUser = getCurrentUser(); if (currentUser != null) { diff --git a/src/main/java/eu/mulk/mulkcms2/benki/posts/PostText.java b/src/main/java/eu/mulk/mulkcms2/benki/posts/PostText.java index 5bc94c8..5e8dd29 100644 --- a/src/main/java/eu/mulk/mulkcms2/benki/posts/PostText.java +++ b/src/main/java/eu/mulk/mulkcms2/benki/posts/PostText.java @@ -18,6 +18,7 @@ import jakarta.persistence.Inheritance; import jakarta.persistence.InheritanceType; import jakarta.persistence.JoinColumn; import jakarta.persistence.ManyToOne; +import jakarta.persistence.MapsId; import jakarta.persistence.Table; import javax.annotation.CheckForNull; import org.hibernate.annotations.Generated; @@ -32,8 +33,8 @@ public abstract class PostText> extends PanacheEntity private static final int DESCRIPTION_CACHE_VERSION = 1; @Id - @Column(name = "post", nullable = false, insertable = false, updatable = false) - public int postId; + @Column(name = "post", nullable = false) + public Integer postId; @Id @Column(name = "language", nullable = false, length = -1) @@ -54,6 +55,7 @@ public abstract class PostText> extends PanacheEntity @ManyToOne(fetch = FetchType.LAZY, targetEntity = Post.class) @JoinColumn(name = "post", referencedColumnName = "id", nullable = false) + @MapsId("postId") @JsonbTransient public OwningPost post; diff --git a/src/main/java/eu/mulk/mulkcms2/benki/posts/PostTextPK.java b/src/main/java/eu/mulk/mulkcms2/benki/posts/PostTextPK.java index 74ad89e..6526526 100644 --- a/src/main/java/eu/mulk/mulkcms2/benki/posts/PostTextPK.java +++ b/src/main/java/eu/mulk/mulkcms2/benki/posts/PostTextPK.java @@ -9,17 +9,17 @@ public class PostTextPK implements Serializable { @Id @Column(name = "post", nullable = false) - private int postId; + private Integer postId; @Id @Column(name = "language", nullable = false, length = -1) private String language; - public int getPostId() { + public Integer getPostId() { return postId; } - public void setPostId(int postId) { + public void setPostId(Integer postId) { this.postId = postId; } -- cgit v1.2.3