From 2f32ef66e9742c23f37df65b096c178879664db3 Mon Sep 17 00:00:00 2001 From: Paulo Gustavo Veiga Date: Sat, 13 Jan 2024 18:49:49 -0800 Subject: [PATCH] Migrate all to entity manager. --- .../wisemapping/config/HibernateConfig.java | 6 -- .../com/wisemapping/dao/LabelManagerImpl.java | 27 +++----- .../wisemapping/dao/MindmapManagerImpl.java | 62 +++++++------------ .../com/wisemapping/dao/UserManagerImpl.java | 44 ++++--------- 4 files changed, 44 insertions(+), 95 deletions(-) diff --git a/wise-webapp/src/main/java/com/wisemapping/config/HibernateConfig.java b/wise-webapp/src/main/java/com/wisemapping/config/HibernateConfig.java index 66ef9847..b5d266b7 100644 --- a/wise-webapp/src/main/java/com/wisemapping/config/HibernateConfig.java +++ b/wise-webapp/src/main/java/com/wisemapping/config/HibernateConfig.java @@ -3,14 +3,8 @@ package com.wisemapping.config; import com.wisemapping.model.User; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.autoconfigure.domain.EntityScan; -import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; import org.springframework.data.jpa.repository.config.EnableJpaRepositories; -import org.springframework.transaction.annotation.EnableTransactionManagement; - -//@Configuration -//@EnableTransactionManagement -//@EnableJpaRepositories("com.wisemapping.model") @Configuration diff --git a/wise-webapp/src/main/java/com/wisemapping/dao/LabelManagerImpl.java b/wise-webapp/src/main/java/com/wisemapping/dao/LabelManagerImpl.java index 733831bc..dd6d7472 100644 --- a/wise-webapp/src/main/java/com/wisemapping/dao/LabelManagerImpl.java +++ b/wise-webapp/src/main/java/com/wisemapping/dao/LabelManagerImpl.java @@ -19,10 +19,8 @@ package com.wisemapping.dao; import com.wisemapping.model.Label; import com.wisemapping.model.User; -import jakarta.annotation.Resource; -import org.hibernate.Session; -import org.hibernate.SessionFactory; -import org.hibernate.query.SelectionQuery; +import jakarta.persistence.EntityManager; +import jakarta.persistence.TypedQuery; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.springframework.beans.factory.annotation.Autowired; @@ -34,7 +32,7 @@ import java.util.List; public class LabelManagerImpl implements LabelManager { @Autowired - private SessionFactory sessionFactory; + private EntityManager entityManager; @Override public void addLabel(@NotNull final Label label) { @@ -43,26 +41,21 @@ public class LabelManagerImpl @Override public void saveLabel(@NotNull final Label label) { - getSession().persist(label); - } - - private Session getSession() { - return sessionFactory.getCurrentSession(); + entityManager.persist(label); } @NotNull @Override public List