From d08574bc53b0e8056fcc5c6d65aad9ab8ff42dea Mon Sep 17 00:00:00 2001 From: ekallin Date: Sun, 14 Apr 2024 23:25:37 +0300 Subject: [PATCH] =?UTF-8?q?=D0=B8=D0=B7=D0=BC=D0=B5=D0=BD=D0=B5=D0=BD?= =?UTF-8?q?=D1=8B=20=D0=B1=D0=B0=D0=B7=D0=BE=D0=B2=D0=B0=D1=8F=20=D1=81?= =?UTF-8?q?=D1=83=D1=89=D0=BD=D0=BE=D1=81=D1=82=D1=8C,=20=D0=BA=D0=BE?= =?UTF-8?q?=D0=BD=D1=81=D1=82=D0=B0=D0=BD=D1=82=D1=8B=20=D0=B8=20=D0=BA?= =?UTF-8?q?=D1=80=D1=83=D0=B4=20=D1=80=D0=B5=D0=BF=D0=BE=D0=B7=D0=B8=D1=82?= =?UTF-8?q?=D0=BE=D1=80=D0=B8=D0=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../core/configurations/Constants.java | 1 + .../backend/core/model/BaseEntity.java | 26 ++++++++++++------- .../favorites/repository/CrudRepository.java | 5 ++++ 3 files changed, 22 insertions(+), 10 deletions(-) create mode 100644 backend/src/main/java/com/example/backend/favorites/repository/CrudRepository.java diff --git a/backend/src/main/java/com/example/backend/core/configurations/Constants.java b/backend/src/main/java/com/example/backend/core/configurations/Constants.java index daaf1ae..c1f0a38 100644 --- a/backend/src/main/java/com/example/backend/core/configurations/Constants.java +++ b/backend/src/main/java/com/example/backend/core/configurations/Constants.java @@ -2,6 +2,7 @@ package com.example.backend.core.configurations; public class Constants { public static final String API_URL = "/api"; + public static final String SEQUENCE_NAME = "hibernate_sequence"; private Constants() { } diff --git a/backend/src/main/java/com/example/backend/core/model/BaseEntity.java b/backend/src/main/java/com/example/backend/core/model/BaseEntity.java index 91a5b54..7bf33e2 100644 --- a/backend/src/main/java/com/example/backend/core/model/BaseEntity.java +++ b/backend/src/main/java/com/example/backend/core/model/BaseEntity.java @@ -1,23 +1,29 @@ package com.example.backend.core.model; -public class BaseEntity { +import com.example.backend.core.configurations.Constants; - public Integer id; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.MappedSuperclass; +import jakarta.persistence.SequenceGenerator; + +@MappedSuperclass +public abstract class BaseEntity { + @Id + @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = Constants.SEQUENCE_NAME) + @SequenceGenerator(name = Constants.SEQUENCE_NAME, sequenceName = Constants.SEQUENCE_NAME, allocationSize = 1) + protected Long id; protected BaseEntity() { - } - protected BaseEntity(Integer id) { - this.id = id; - } - - public Integer getId() { + public Long getId() { return id; } - public void setId(Integer id) { + public void setId(Long id) { this.id = id; } - } + diff --git a/backend/src/main/java/com/example/backend/favorites/repository/CrudRepository.java b/backend/src/main/java/com/example/backend/favorites/repository/CrudRepository.java new file mode 100644 index 0000000..7e63514 --- /dev/null +++ b/backend/src/main/java/com/example/backend/favorites/repository/CrudRepository.java @@ -0,0 +1,5 @@ +package com.example.backend.favorites.repository; + +public class CrudRepository { + +}