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 3ee0d9d3e..f1c88a925 100644 --- a/cqrs/src/main/java/com/iluwatar/cqrs/commandes/CommandServiceImpl.java +++ b/cqrs/src/main/java/com/iluwatar/cqrs/commandes/CommandServiceImpl.java @@ -23,6 +23,9 @@ public class CommandServiceImpl implements ICommandService { query.setParameter("username", username); author = (Author) query.uniqueResult(); } + if (author == null) { + throw new NullPointerException("Author " + username + " doesn't exist!"); + } return author; } @@ -33,6 +36,9 @@ public class CommandServiceImpl implements ICommandService { query.setParameter("title", title); book = (Book) query.uniqueResult(); } + if (book == null) { + throw new NullPointerException("Book " + title + " doesn't exist!"); + } return book; }