From 871df4f91893da869715fc7c41b0ac481d04bf36 Mon Sep 17 00:00:00 2001 From: Sabiq Ihab Date: Sat, 29 Jul 2017 13:26:54 +0100 Subject: [PATCH] close connection before throwing an exception --- .../java/com/iluwatar/cqrs/commandes/CommandServiceImpl.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/cqrs/src/main/java/com/iluwatar/cqrs/commandes/CommandServiceImpl.java b/cqrs/src/main/java/com/iluwatar/cqrs/commandes/CommandServiceImpl.java index f1c88a925..86d9cb10b 100644 --- a/cqrs/src/main/java/com/iluwatar/cqrs/commandes/CommandServiceImpl.java +++ b/cqrs/src/main/java/com/iluwatar/cqrs/commandes/CommandServiceImpl.java @@ -24,6 +24,7 @@ public class CommandServiceImpl implements ICommandService { author = (Author) query.uniqueResult(); } if (author == null) { + HibernateUtil.getSessionFactory().close(); throw new NullPointerException("Author " + username + " doesn't exist!"); } return author; @@ -37,6 +38,7 @@ public class CommandServiceImpl implements ICommandService { book = (Book) query.uniqueResult(); } if (book == null) { + HibernateUtil.getSessionFactory().close(); throw new NullPointerException("Book " + title + " doesn't exist!"); } return book;