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

Migrate to Hibernate 6 - use dedicated table sequences #691

Merged
merged 1 commit into from
Mar 1, 2023
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
Original file line number Diff line number Diff line change
@@ -1,14 +1,22 @@
package io.quarkus.qe.database.mysql;

import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.Table;
import jakarta.validation.constraints.NotBlank;

import io.quarkus.hibernate.orm.panache.PanacheEntity;
import io.quarkus.hibernate.orm.panache.PanacheEntityBase;

@Entity
@Table(name = "book")
public class Book extends PanacheEntity {
public class Book extends PanacheEntityBase {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
public Long id;

@NotBlank(message = "book title must be set")
public String title;

Expand Down
15 changes: 7 additions & 8 deletions examples/database-mysql/src/main/resources/import.sql
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
INSERT INTO book (id, title, author) VALUES (1, 'Foundation', 'Isaac Asimov');
INSERT INTO book (id, title, author) VALUES (2, '2001: A Space Odyssey', 'Arthur C. Clarke');
INSERT INTO book (id, title, author) VALUES (3, 'Stranger in a Strange Land', 'Robert A. Heinlein');
INSERT INTO book (id, title, author) VALUES (4, 'Ender''s Game', 'Orson Scott Card');
INSERT INTO book (id, title, author) VALUES (5, 'Hyperion', 'Dan Simmons');
INSERT INTO book (id, title, author) VALUES (6, 'Anathem', 'Neal Stephenson');
INSERT INTO book (id, title, author) VALUES (7, 'Perdido Street Station', 'China Miéville');
UPDATE hibernate_sequence SET next_val = 8;
INSERT INTO book (title, author) VALUES ('Foundation', 'Isaac Asimov');
INSERT INTO book (title, author) VALUES ('2001: A Space Odyssey', 'Arthur C. Clarke');
INSERT INTO book (title, author) VALUES ('Stranger in a Strange Land', 'Robert A. Heinlein');
INSERT INTO book (title, author) VALUES ('Ender''s Game', 'Orson Scott Card');
INSERT INTO book (title, author) VALUES ('Hyperion', 'Dan Simmons');
INSERT INTO book (title, author) VALUES ('Anathem', 'Neal Stephenson');
INSERT INTO book (title, author) VALUES ('Perdido Street Station', 'China Miéville');
15 changes: 7 additions & 8 deletions examples/database-mysql/src/test/resources/import-in-test.sql
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
INSERT INTO book (id, title, author) VALUES (1, 'Foundation', 'Isaac Asimov');
INSERT INTO book (id, title, author) VALUES (2, '2001: A Space Odyssey', 'Arthur C. Clarke');
INSERT INTO book (id, title, author) VALUES (3, 'Stranger in a Strange Land', 'Robert A. Heinlein');
INSERT INTO book (id, title, author) VALUES (4, 'Ender''s Game', 'Orson Scott Card');
INSERT INTO book (id, title, author) VALUES (5, 'Hyperion', 'Dan Simmons');
INSERT INTO book (id, title, author) VALUES (6, 'Anathem', 'Neal Stephenson');
INSERT INTO book (id, title, author) VALUES (7, 'Perdido Street Station', 'China Miéville');
UPDATE hibernate_sequence SET next_val = 8;
INSERT INTO book (title, author) VALUES ('Foundation', 'Isaac Asimov');
INSERT INTO book (title, author) VALUES ('2001: A Space Odyssey', 'Arthur C. Clarke');
INSERT INTO book (title, author) VALUES ('Stranger in a Strange Land', 'Robert A. Heinlein');
INSERT INTO book (title, author) VALUES ('Ender''s Game', 'Orson Scott Card');
INSERT INTO book (title, author) VALUES ('Hyperion', 'Dan Simmons');
INSERT INTO book (title, author) VALUES ('Anathem', 'Neal Stephenson');
INSERT INTO book (title, author) VALUES ('Perdido Street Station', 'China Miéville');
Original file line number Diff line number Diff line change
@@ -1,14 +1,24 @@
package io.quarkus.qe.database.oracle;

import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.SequenceGenerator;
import jakarta.persistence.Table;
import jakarta.validation.constraints.NotBlank;

import io.quarkus.hibernate.orm.panache.PanacheEntity;
import io.quarkus.hibernate.orm.panache.PanacheEntityBase;

@Entity
@Table(name = "book")
public class Book extends PanacheEntity {
public class Book extends PanacheEntityBase {

@Id
@SequenceGenerator(name = "bookSequence", sequenceName = "Book_SEQ", allocationSize = 1)
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "bookSequence")
public Long id;

@NotBlank(message = "book title must be set")
public String title;

Expand Down
14 changes: 7 additions & 7 deletions examples/database-oracle/src/main/resources/import.sql
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
INSERT INTO book (id, title, author) VALUES (hibernate_sequence.NEXTVAL, 'Foundation', 'Isaac Asimov');
INSERT INTO book (id, title, author) VALUES (hibernate_sequence.NEXTVAL, '2001: A Space Odyssey', 'Arthur C. Clarke');
INSERT INTO book (id, title, author) VALUES (hibernate_sequence.NEXTVAL, 'Stranger in a Strange Land', 'Robert A. Heinlein');
INSERT INTO book (id, title, author) VALUES (hibernate_sequence.NEXTVAL, 'Ender''s Game', 'Orson Scott Card');
INSERT INTO book (id, title, author) VALUES (hibernate_sequence.NEXTVAL, 'Hyperion', 'Dan Simmons');
INSERT INTO book (id, title, author) VALUES (hibernate_sequence.NEXTVAL, 'Anathem', 'Neal Stephenson');
INSERT INTO book (id, title, author) VALUES (hibernate_sequence.NEXTVAL, 'Perdido Street Station', 'China Miéville');
INSERT INTO book (id, title, author) VALUES (Book_SEQ.NEXTVAL, 'Foundation', 'Isaac Asimov');
INSERT INTO book (id, title, author) VALUES (Book_SEQ.NEXTVAL, '2001: A Space Odyssey', 'Arthur C. Clarke');
INSERT INTO book (id, title, author) VALUES (Book_SEQ.NEXTVAL, 'Stranger in a Strange Land', 'Robert A. Heinlein');
INSERT INTO book (id, title, author) VALUES (Book_SEQ.NEXTVAL, 'Ender''s Game', 'Orson Scott Card');
INSERT INTO book (id, title, author) VALUES (Book_SEQ.NEXTVAL, 'Hyperion', 'Dan Simmons');
INSERT INTO book (id, title, author) VALUES (Book_SEQ.NEXTVAL, 'Anathem', 'Neal Stephenson');
INSERT INTO book (id, title, author) VALUES (Book_SEQ.NEXTVAL, 'Perdido Street Station', 'China Miéville');
14 changes: 7 additions & 7 deletions examples/database-oracle/src/test/resources/import-in-test.sql
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
INSERT INTO book (id, title, author) VALUES (hibernate_sequence.NEXTVAL, 'Foundation', 'Isaac Asimov');
INSERT INTO book (id, title, author) VALUES (hibernate_sequence.NEXTVAL, '2001: A Space Odyssey', 'Arthur C. Clarke');
INSERT INTO book (id, title, author) VALUES (hibernate_sequence.NEXTVAL, 'Stranger in a Strange Land', 'Robert A. Heinlein');
INSERT INTO book (id, title, author) VALUES (hibernate_sequence.NEXTVAL, 'Ender''s Game', 'Orson Scott Card');
INSERT INTO book (id, title, author) VALUES (hibernate_sequence.NEXTVAL, 'Hyperion', 'Dan Simmons');
INSERT INTO book (id, title, author) VALUES (hibernate_sequence.NEXTVAL, 'Anathem', 'Neal Stephenson');
INSERT INTO book (id, title, author) VALUES (hibernate_sequence.NEXTVAL, 'Perdido Street Station', 'China Miéville');
INSERT INTO book (id, title, author) VALUES (Book_SEQ.NEXTVAL, 'Foundation', 'Isaac Asimov');
INSERT INTO book (id, title, author) VALUES (Book_SEQ.NEXTVAL, '2001: A Space Odyssey', 'Arthur C. Clarke');
INSERT INTO book (id, title, author) VALUES (Book_SEQ.NEXTVAL, 'Stranger in a Strange Land', 'Robert A. Heinlein');
INSERT INTO book (id, title, author) VALUES (Book_SEQ.NEXTVAL, 'Ender''s Game', 'Orson Scott Card');
INSERT INTO book (id, title, author) VALUES (Book_SEQ.NEXTVAL, 'Hyperion', 'Dan Simmons');
INSERT INTO book (id, title, author) VALUES (Book_SEQ.NEXTVAL, 'Anathem', 'Neal Stephenson');
INSERT INTO book (id, title, author) VALUES (Book_SEQ.NEXTVAL, 'Perdido Street Station', 'China Miéville');
Original file line number Diff line number Diff line change
@@ -1,14 +1,24 @@
package io.quarkus.qe.database.postgresql;

import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.SequenceGenerator;
import jakarta.persistence.Table;
import jakarta.validation.constraints.NotBlank;

import io.quarkus.hibernate.orm.panache.PanacheEntity;
import io.quarkus.hibernate.orm.panache.PanacheEntityBase;

@Entity
@Table(name = "book")
public class Book extends PanacheEntity {
public class Book extends PanacheEntityBase {

@Id
@SequenceGenerator(name = "bookSequence", sequenceName = "Book_SEQ", allocationSize = 1)
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "bookSequence")
public Long id;

@NotBlank(message = "book title must be set")
public String title;

Expand Down
14 changes: 7 additions & 7 deletions examples/database-postgresql/src/main/resources/import.sql
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
INSERT INTO book (id, title, author) VALUES (nextval('hibernate_sequence'), 'Foundation', 'Isaac Asimov');
INSERT INTO book (id, title, author) VALUES (nextval('hibernate_sequence'), '2001: A Space Odyssey', 'Arthur C. Clarke');
INSERT INTO book (id, title, author) VALUES (nextval('hibernate_sequence'), 'Stranger in a Strange Land', 'Robert A. Heinlein');
INSERT INTO book (id, title, author) VALUES (nextval('hibernate_sequence'), 'Ender''s Game', 'Orson Scott Card');
INSERT INTO book (id, title, author) VALUES (nextval('hibernate_sequence'), 'Hyperion', 'Dan Simmons');
INSERT INTO book (id, title, author) VALUES (nextval('hibernate_sequence'), 'Anathem', 'Neal Stephenson');
INSERT INTO book (id, title, author) VALUES (nextval('hibernate_sequence'), 'Perdido Street Station', 'China Miéville');
INSERT INTO book (id, title, author) VALUES (nextval('Book_SEQ'), 'Foundation', 'Isaac Asimov');
INSERT INTO book (id, title, author) VALUES (nextval('Book_SEQ'), '2001: A Space Odyssey', 'Arthur C. Clarke');
INSERT INTO book (id, title, author) VALUES (nextval('Book_SEQ'), 'Stranger in a Strange Land', 'Robert A. Heinlein');
INSERT INTO book (id, title, author) VALUES (nextval('Book_SEQ'), 'Ender''s Game', 'Orson Scott Card');
INSERT INTO book (id, title, author) VALUES (nextval('Book_SEQ'), 'Hyperion', 'Dan Simmons');
INSERT INTO book (id, title, author) VALUES (nextval('Book_SEQ'), 'Anathem', 'Neal Stephenson');
INSERT INTO book (id, title, author) VALUES (nextval('Book_SEQ'), 'Perdido Street Station', 'China Miéville');
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
INSERT INTO book (id, title, author) VALUES (nextval('hibernate_sequence'), 'Foundation', 'Isaac Asimov');
INSERT INTO book (id, title, author) VALUES (nextval('hibernate_sequence'), '2001: A Space Odyssey', 'Arthur C. Clarke');
INSERT INTO book (id, title, author) VALUES (nextval('hibernate_sequence'), 'Stranger in a Strange Land', 'Robert A. Heinlein');
INSERT INTO book (id, title, author) VALUES (nextval('hibernate_sequence'), 'Ender''s Game', 'Orson Scott Card');
INSERT INTO book (id, title, author) VALUES (nextval('hibernate_sequence'), 'Hyperion', 'Dan Simmons');
INSERT INTO book (id, title, author) VALUES (nextval('hibernate_sequence'), 'Anathem', 'Neal Stephenson');
INSERT INTO book (id, title, author) VALUES (nextval('hibernate_sequence'), 'Perdido Street Station', 'China Miéville');
INSERT INTO book (id, title, author) VALUES (nextval('Book_SEQ'), 'Foundation', 'Isaac Asimov');
INSERT INTO book (id, title, author) VALUES (nextval('Book_SEQ'), '2001: A Space Odyssey', 'Arthur C. Clarke');
INSERT INTO book (id, title, author) VALUES (nextval('Book_SEQ'), 'Stranger in a Strange Land', 'Robert A. Heinlein');
INSERT INTO book (id, title, author) VALUES (nextval('Book_SEQ'), 'Ender''s Game', 'Orson Scott Card');
INSERT INTO book (id, title, author) VALUES (nextval('Book_SEQ'), 'Hyperion', 'Dan Simmons');
INSERT INTO book (id, title, author) VALUES (nextval('Book_SEQ'), 'Anathem', 'Neal Stephenson');
INSERT INTO book (id, title, author) VALUES (nextval('Book_SEQ'), 'Perdido Street Station', 'China Miéville');