Skip to content

Commit 871df4f

Browse files
committed
close connection before throwing an exception
1 parent 7ae9e3e commit 871df4f

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

cqrs/src/main/java/com/iluwatar/cqrs/commandes/CommandServiceImpl.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ private Author getAuthorByUsername(String username) {
2424
author = (Author) query.uniqueResult();
2525
}
2626
if (author == null) {
27+
HibernateUtil.getSessionFactory().close();
2728
throw new NullPointerException("Author " + username + " doesn't exist!");
2829
}
2930
return author;
@@ -37,6 +38,7 @@ private Book getBookByTitle(String title) {
3738
book = (Book) query.uniqueResult();
3839
}
3940
if (book == null) {
41+
HibernateUtil.getSessionFactory().close();
4042
throw new NullPointerException("Book " + title + " doesn't exist!");
4143
}
4244
return book;

0 commit comments

Comments
 (0)