More Hibernate 6.2 compatibility.

Change-Id: Ib06822de4e2d64419a8285c0a46b2d8931cea4c8
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 @@
     if (text == null) {
       text = new BookmarkText();
       text.post = this;
+      text.postId = id;
       text.language = "";
       texts.put(text.language, text);
     }
@@ -72,6 +73,7 @@
     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 @@
     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 @@
     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 @@
     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 @@
     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.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 @@
   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 @@
 
   @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 @@
 
   @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;
   }