From 53017c54a64c5ef58fceb4107e373b3ae6924d45 Mon Sep 17 00:00:00 2001 From: Bohdan Date: Mon, 26 Aug 2024 13:55:05 +0300 Subject: [PATCH] Help me with tests --- mem.lck | Bin 16 -> 16 bytes src/main/java/mate/academy/dao/MovieDaoImpl.java | 3 ++- .../java/mate/academy/util/HibernateUtil.java | 4 ++++ src/main/resources/hibernate.cfg.xml | 2 +- 4 files changed, 7 insertions(+), 2 deletions(-) diff --git a/mem.lck b/mem.lck index 06618df4373696bfd67fadd62099692b7fc01860..00f7c72bdba694d03efe0516697767f980feb920 100644 GIT binary patch literal 16 XcmeYW4)pQyclKsrV4T<&*c1r>B~S#e literal 16 XcmeYW4)pQyclKsrV4T?XMy&||CV~YL diff --git a/src/main/java/mate/academy/dao/MovieDaoImpl.java b/src/main/java/mate/academy/dao/MovieDaoImpl.java index 7099d8a29..98f4ae1a9 100644 --- a/src/main/java/mate/academy/dao/MovieDaoImpl.java +++ b/src/main/java/mate/academy/dao/MovieDaoImpl.java @@ -19,10 +19,11 @@ public Movie add(Movie movie) { transaction = session.beginTransaction(); session.persist(movie); transaction.commit(); - } catch (DataProcessingException e) { + } catch (Exception e) { if (transaction != null) { transaction.rollback(); } + throw new DataProcessingException("error while adding movie", e); } finally { if (session != null) { session.close(); diff --git a/src/main/java/mate/academy/util/HibernateUtil.java b/src/main/java/mate/academy/util/HibernateUtil.java index df3a01328..682ff26e3 100644 --- a/src/main/java/mate/academy/util/HibernateUtil.java +++ b/src/main/java/mate/academy/util/HibernateUtil.java @@ -6,6 +6,10 @@ public class HibernateUtil { private static final SessionFactory sessionFactory = initSessionFactory(); + private HibernateUtil() { + + } + private static SessionFactory initSessionFactory() { return new Configuration().configure().buildSessionFactory(); } diff --git a/src/main/resources/hibernate.cfg.xml b/src/main/resources/hibernate.cfg.xml index 966acb070..b8d1376c5 100644 --- a/src/main/resources/hibernate.cfg.xml +++ b/src/main/resources/hibernate.cfg.xml @@ -1,7 +1,7 @@ - org.hibernate.dialect.MySQLDialect + org.hibernate.dialect.MySQL8Dialect jdbc:mysql://localhost:3306/test?serverTimezone=UTC com.mysql.cj.jdbc.Driver root