From 0246c3e491685e7e3169615c526d627ed989f353 Mon Sep 17 00:00:00 2001 From: Matthias Andreas Benkard Date: Mon, 27 Jan 2020 05:39:08 +0100 Subject: Data model mapping: Mark all ID fields @GeneratedValue, make boxed. - Marks all SERIAL columns with @GeneratedValue. - Makes all SERIAL columns type Integer instead of type int. This enables Hibernate to autogenerate values on insert. Change-Id: I826d3a58e065c3dd3fa5f588a23226dfe954fb7d --- src/main/java/eu/mulk/mulkcms2/benki/accesscontrol/Role.java | 5 ++++- src/main/java/eu/mulk/mulkcms2/benki/generic/Post.java | 11 ++++++++++- src/main/java/eu/mulk/mulkcms2/benki/users/User.java | 6 ++++-- src/main/java/eu/mulk/mulkcms2/benki/wiki/WikiPage.java | 5 ++++- .../java/eu/mulk/mulkcms2/benki/wiki/WikiPageRevision.java | 5 ++++- src/main/java/eu/mulk/mulkcms2/cms/comments/Comment.java | 5 ++++- .../java/eu/mulk/mulkcms2/cms/comments/CommentRevision.java | 5 ++++- src/main/java/eu/mulk/mulkcms2/cms/journal/Journal.java | 5 ++++- .../mulkcms2/cms/legacyjournal/LegacyJournalCategory.java | 5 ++++- .../mulk/mulkcms2/cms/legacyjournal/LegacyJournalComment.java | 5 ++++- .../mulk/mulkcms2/cms/legacyjournal/LegacyJournalEntry.java | 5 ++++- .../mulkcms2/cms/legacyjournal/LegacyJournalPingback.java | 5 ++++- .../mulkcms2/cms/legacyjournal/LegacyJournalTrackback.java | 5 ++++- src/main/java/eu/mulk/mulkcms2/cms/pages/Article.java | 5 ++++- src/main/java/eu/mulk/mulkcms2/cms/pages/ArticleRevision.java | 5 ++++- src/main/java/eu/mulk/mulkcms2/cms/pages/ArticleType.java | 5 ++++- src/main/java/eu/mulk/mulkcms2/cms/pages/Category.java | 5 ++++- src/main/java/eu/mulk/mulkcms2/cms/users/User.java | 5 ++++- 18 files changed, 78 insertions(+), 19 deletions(-) (limited to 'src/main') diff --git a/src/main/java/eu/mulk/mulkcms2/benki/accesscontrol/Role.java b/src/main/java/eu/mulk/mulkcms2/benki/accesscontrol/Role.java index 200997e..b3efeb9 100644 --- a/src/main/java/eu/mulk/mulkcms2/benki/accesscontrol/Role.java +++ b/src/main/java/eu/mulk/mulkcms2/benki/accesscontrol/Role.java @@ -12,6 +12,8 @@ import javax.persistence.Column; import javax.persistence.ElementCollection; import javax.persistence.Entity; import javax.persistence.FetchType; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; import javax.persistence.Id; import javax.persistence.JoinColumn; import javax.persistence.JoinTable; @@ -25,8 +27,9 @@ import javax.persistence.Table; public class Role extends PanacheEntityBase { @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = "id", nullable = false) - public int id; + public Integer id; @Column(name = "name", nullable = true, length = -1) public String name; diff --git a/src/main/java/eu/mulk/mulkcms2/benki/generic/Post.java b/src/main/java/eu/mulk/mulkcms2/benki/generic/Post.java index 309fb67..596a6f7 100644 --- a/src/main/java/eu/mulk/mulkcms2/benki/generic/Post.java +++ b/src/main/java/eu/mulk/mulkcms2/benki/generic/Post.java @@ -7,6 +7,8 @@ import java.util.Set; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.FetchType; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; import javax.persistence.Id; import javax.persistence.Inheritance; import javax.persistence.InheritanceType; @@ -14,6 +16,7 @@ import javax.persistence.JoinColumn; import javax.persistence.JoinTable; import javax.persistence.ManyToMany; import javax.persistence.ManyToOne; +import javax.persistence.SequenceGenerator; import javax.persistence.Table; @Entity @@ -22,8 +25,14 @@ import javax.persistence.Table; public abstract class Post extends PanacheEntityBase { @Id + @SequenceGenerator( + allocationSize = 1, + sequenceName = "posts_id_seq", + name = "posts_id_seq", + schema = "benki") + @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "posts_id_seq") @Column(name = "id", nullable = false) - public int id; + public Integer id; @Column(name = "date", nullable = true) public OffsetDateTime date; diff --git a/src/main/java/eu/mulk/mulkcms2/benki/users/User.java b/src/main/java/eu/mulk/mulkcms2/benki/users/User.java index 40e5364..72a63f6 100644 --- a/src/main/java/eu/mulk/mulkcms2/benki/users/User.java +++ b/src/main/java/eu/mulk/mulkcms2/benki/users/User.java @@ -14,9 +14,10 @@ import javax.persistence.Column; import javax.persistence.ElementCollection; import javax.persistence.Entity; import javax.persistence.FetchType; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; import javax.persistence.Id; import javax.persistence.JoinColumn; -import javax.persistence.JoinColumns; import javax.persistence.JoinTable; import javax.persistence.ManyToMany; import javax.persistence.OneToMany; @@ -28,8 +29,9 @@ import javax.persistence.Table; public class User extends PanacheEntityBase { @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = "id", nullable = false) - public int id; + public Integer id; @Column(name = "first_name", nullable = true, length = -1) public String firstName; diff --git a/src/main/java/eu/mulk/mulkcms2/benki/wiki/WikiPage.java b/src/main/java/eu/mulk/mulkcms2/benki/wiki/WikiPage.java index 9b40d5d..b627f9a 100644 --- a/src/main/java/eu/mulk/mulkcms2/benki/wiki/WikiPage.java +++ b/src/main/java/eu/mulk/mulkcms2/benki/wiki/WikiPage.java @@ -5,6 +5,8 @@ import java.util.List; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.FetchType; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; import javax.persistence.Id; import javax.persistence.OneToMany; import javax.persistence.OrderBy; @@ -16,7 +18,8 @@ public class WikiPage extends PanacheEntityBase { @Id @Column(name = "id", nullable = false) - public int id; + @GeneratedValue(strategy = GenerationType.IDENTITY) + public Integer id; @OneToMany(mappedBy = "page", fetch = FetchType.LAZY) @OrderBy("date desc") diff --git a/src/main/java/eu/mulk/mulkcms2/benki/wiki/WikiPageRevision.java b/src/main/java/eu/mulk/mulkcms2/benki/wiki/WikiPageRevision.java index c6bcf5f..5783166 100644 --- a/src/main/java/eu/mulk/mulkcms2/benki/wiki/WikiPageRevision.java +++ b/src/main/java/eu/mulk/mulkcms2/benki/wiki/WikiPageRevision.java @@ -6,6 +6,8 @@ import java.time.OffsetDateTime; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.FetchType; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; import javax.persistence.Id; import javax.persistence.JoinColumn; import javax.persistence.ManyToOne; @@ -16,8 +18,9 @@ import javax.persistence.Table; public class WikiPageRevision extends PanacheEntityBase { @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = "id", nullable = false) - public int id; + public Integer id; @Column(name = "date", nullable = true) public OffsetDateTime date; diff --git a/src/main/java/eu/mulk/mulkcms2/cms/comments/Comment.java b/src/main/java/eu/mulk/mulkcms2/cms/comments/Comment.java index 0843c12..11df62b 100644 --- a/src/main/java/eu/mulk/mulkcms2/cms/comments/Comment.java +++ b/src/main/java/eu/mulk/mulkcms2/cms/comments/Comment.java @@ -6,6 +6,8 @@ import java.util.Collection; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.FetchType; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; import javax.persistence.Id; import javax.persistence.JoinColumn; import javax.persistence.ManyToOne; @@ -17,8 +19,9 @@ import javax.persistence.Table; public class Comment extends PanacheEntityBase { @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = "id", nullable = false) - public int id; + public Integer id; @Column(name = "global_id", nullable = true, length = -1) public String globalId; diff --git a/src/main/java/eu/mulk/mulkcms2/cms/comments/CommentRevision.java b/src/main/java/eu/mulk/mulkcms2/cms/comments/CommentRevision.java index 2c6f6e4..7d642d4 100644 --- a/src/main/java/eu/mulk/mulkcms2/cms/comments/CommentRevision.java +++ b/src/main/java/eu/mulk/mulkcms2/cms/comments/CommentRevision.java @@ -8,6 +8,8 @@ import java.sql.Timestamp; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.FetchType; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; import javax.persistence.Id; import javax.persistence.JoinColumn; import javax.persistence.ManyToOne; @@ -20,8 +22,9 @@ import org.hibernate.annotations.TypeDef; public class CommentRevision extends PanacheEntityBase { @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = "id", nullable = false) - public int id; + public Integer id; @Column(name = "date", nullable = true) public Timestamp date; diff --git a/src/main/java/eu/mulk/mulkcms2/cms/journal/Journal.java b/src/main/java/eu/mulk/mulkcms2/cms/journal/Journal.java index f3732a7..fe11ca0 100644 --- a/src/main/java/eu/mulk/mulkcms2/cms/journal/Journal.java +++ b/src/main/java/eu/mulk/mulkcms2/cms/journal/Journal.java @@ -5,6 +5,8 @@ import java.util.Collection; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.FetchType; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; import javax.persistence.Id; import javax.persistence.OneToMany; import javax.persistence.Table; @@ -14,8 +16,9 @@ import javax.persistence.Table; public class Journal extends PanacheEntityBase { @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = "id", nullable = false) - public int id; + public Integer id; @Column(name = "path_prefix", nullable = true, length = -1) public String pathPrefix; diff --git a/src/main/java/eu/mulk/mulkcms2/cms/legacyjournal/LegacyJournalCategory.java b/src/main/java/eu/mulk/mulkcms2/cms/legacyjournal/LegacyJournalCategory.java index 92cc3df..31a968e 100644 --- a/src/main/java/eu/mulk/mulkcms2/cms/legacyjournal/LegacyJournalCategory.java +++ b/src/main/java/eu/mulk/mulkcms2/cms/legacyjournal/LegacyJournalCategory.java @@ -3,6 +3,8 @@ package eu.mulk.mulkcms2.cms.legacyjournal; import io.quarkus.hibernate.orm.panache.PanacheEntityBase; import javax.persistence.Column; import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; import javax.persistence.Id; import javax.persistence.Table; @@ -11,8 +13,9 @@ import javax.persistence.Table; public class LegacyJournalCategory extends PanacheEntityBase { @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = "id", nullable = false) - public int id; + public Integer id; @Column(name = "uuid", nullable = false, length = 36) public String uuid; diff --git a/src/main/java/eu/mulk/mulkcms2/cms/legacyjournal/LegacyJournalComment.java b/src/main/java/eu/mulk/mulkcms2/cms/legacyjournal/LegacyJournalComment.java index f3ecc5c..06ca820 100644 --- a/src/main/java/eu/mulk/mulkcms2/cms/legacyjournal/LegacyJournalComment.java +++ b/src/main/java/eu/mulk/mulkcms2/cms/legacyjournal/LegacyJournalComment.java @@ -4,6 +4,8 @@ import io.quarkus.hibernate.orm.panache.PanacheEntityBase; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.FetchType; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; import javax.persistence.Id; import javax.persistence.JoinColumn; import javax.persistence.ManyToOne; @@ -14,8 +16,9 @@ import javax.persistence.Table; public class LegacyJournalComment extends PanacheEntityBase { @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = "id", nullable = false) - public int id; + public Integer id; @Column(name = "uuid", nullable = false, length = 36) public String uuid; diff --git a/src/main/java/eu/mulk/mulkcms2/cms/legacyjournal/LegacyJournalEntry.java b/src/main/java/eu/mulk/mulkcms2/cms/legacyjournal/LegacyJournalEntry.java index 0038f97..fcbf895 100644 --- a/src/main/java/eu/mulk/mulkcms2/cms/legacyjournal/LegacyJournalEntry.java +++ b/src/main/java/eu/mulk/mulkcms2/cms/legacyjournal/LegacyJournalEntry.java @@ -5,6 +5,8 @@ import java.util.Collection; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.FetchType; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; import javax.persistence.Id; import javax.persistence.OneToMany; import javax.persistence.Table; @@ -14,8 +16,9 @@ import javax.persistence.Table; public class LegacyJournalEntry extends PanacheEntityBase { @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = "id", nullable = false) - public int id; + public Integer id; @Column(name = "uuid", nullable = false, length = 36) public String uuid; diff --git a/src/main/java/eu/mulk/mulkcms2/cms/legacyjournal/LegacyJournalPingback.java b/src/main/java/eu/mulk/mulkcms2/cms/legacyjournal/LegacyJournalPingback.java index 6f0022b..2d2702b 100644 --- a/src/main/java/eu/mulk/mulkcms2/cms/legacyjournal/LegacyJournalPingback.java +++ b/src/main/java/eu/mulk/mulkcms2/cms/legacyjournal/LegacyJournalPingback.java @@ -4,6 +4,8 @@ import io.quarkus.hibernate.orm.panache.PanacheEntityBase; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.FetchType; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; import javax.persistence.Id; import javax.persistence.JoinColumn; import javax.persistence.ManyToOne; @@ -14,8 +16,9 @@ import javax.persistence.Table; public class LegacyJournalPingback extends PanacheEntityBase { @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = "id", nullable = false) - public int id; + public Integer id; @Column(name = "uuid", nullable = false, length = 36) public String uuid; diff --git a/src/main/java/eu/mulk/mulkcms2/cms/legacyjournal/LegacyJournalTrackback.java b/src/main/java/eu/mulk/mulkcms2/cms/legacyjournal/LegacyJournalTrackback.java index 3d9c500..618a2e3 100644 --- a/src/main/java/eu/mulk/mulkcms2/cms/legacyjournal/LegacyJournalTrackback.java +++ b/src/main/java/eu/mulk/mulkcms2/cms/legacyjournal/LegacyJournalTrackback.java @@ -4,6 +4,8 @@ import io.quarkus.hibernate.orm.panache.PanacheEntityBase; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.FetchType; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; import javax.persistence.Id; import javax.persistence.JoinColumn; import javax.persistence.ManyToOne; @@ -14,8 +16,9 @@ import javax.persistence.Table; public class LegacyJournalTrackback extends PanacheEntityBase { @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = "id", nullable = false) - public int id; + public Integer id; @Column(name = "uuid", nullable = false, length = 36) public String uuid; diff --git a/src/main/java/eu/mulk/mulkcms2/cms/pages/Article.java b/src/main/java/eu/mulk/mulkcms2/cms/pages/Article.java index 100c730..c3772f0 100644 --- a/src/main/java/eu/mulk/mulkcms2/cms/pages/Article.java +++ b/src/main/java/eu/mulk/mulkcms2/cms/pages/Article.java @@ -8,6 +8,8 @@ import java.util.Set; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.FetchType; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; import javax.persistence.Id; import javax.persistence.JoinColumn; import javax.persistence.JoinTable; @@ -21,8 +23,9 @@ import javax.persistence.Table; public class Article extends PanacheEntityBase { @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = "id", nullable = false) - public int id; + public Integer id; @OneToMany(mappedBy = "article", fetch = FetchType.LAZY) public Collection aliases; diff --git a/src/main/java/eu/mulk/mulkcms2/cms/pages/ArticleRevision.java b/src/main/java/eu/mulk/mulkcms2/cms/pages/ArticleRevision.java index 670df90..2034e35 100644 --- a/src/main/java/eu/mulk/mulkcms2/cms/pages/ArticleRevision.java +++ b/src/main/java/eu/mulk/mulkcms2/cms/pages/ArticleRevision.java @@ -8,6 +8,8 @@ import java.util.Set; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.FetchType; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; import javax.persistence.Id; import javax.persistence.JoinColumn; import javax.persistence.JoinTable; @@ -21,8 +23,9 @@ import javax.persistence.Table; public class ArticleRevision extends PanacheEntityBase { @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = "id", nullable = false) - public int id; + public Integer id; @Column(name = "date", nullable = true) public Timestamp date; diff --git a/src/main/java/eu/mulk/mulkcms2/cms/pages/ArticleType.java b/src/main/java/eu/mulk/mulkcms2/cms/pages/ArticleType.java index d3d3100..c59acaa 100644 --- a/src/main/java/eu/mulk/mulkcms2/cms/pages/ArticleType.java +++ b/src/main/java/eu/mulk/mulkcms2/cms/pages/ArticleType.java @@ -5,6 +5,8 @@ import java.util.Collection; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.FetchType; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; import javax.persistence.Id; import javax.persistence.OneToMany; import javax.persistence.Table; @@ -14,8 +16,9 @@ import javax.persistence.Table; public class ArticleType extends PanacheEntityBase { @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = "id", nullable = false) - public int id; + public Integer id; @Column(name = "name", nullable = true, length = -1) public String name; diff --git a/src/main/java/eu/mulk/mulkcms2/cms/pages/Category.java b/src/main/java/eu/mulk/mulkcms2/cms/pages/Category.java index 1f5902f..2801c98 100644 --- a/src/main/java/eu/mulk/mulkcms2/cms/pages/Category.java +++ b/src/main/java/eu/mulk/mulkcms2/cms/pages/Category.java @@ -5,6 +5,8 @@ import java.util.Set; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.FetchType; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; import javax.persistence.Id; import javax.persistence.JoinColumn; import javax.persistence.JoinTable; @@ -16,8 +18,9 @@ import javax.persistence.Table; public class Category extends PanacheEntityBase { @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = "id", nullable = false) - public int id; + public Integer id; @Column(name = "name", nullable = false, length = -1) public String name; diff --git a/src/main/java/eu/mulk/mulkcms2/cms/users/User.java b/src/main/java/eu/mulk/mulkcms2/cms/users/User.java index 41e252c..929bc67 100644 --- a/src/main/java/eu/mulk/mulkcms2/cms/users/User.java +++ b/src/main/java/eu/mulk/mulkcms2/cms/users/User.java @@ -7,6 +7,8 @@ import java.util.Collection; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.FetchType; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; import javax.persistence.Id; import javax.persistence.OneToMany; import javax.persistence.Table; @@ -16,8 +18,9 @@ import javax.persistence.Table; public class User extends PanacheEntityBase { @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = "id", nullable = false) - public int id; + public Integer id; @Column(name = "name", nullable = true, length = -1) public String name; -- cgit v1.2.3