public Connection saveChatMessage(Connection con, String message) throws NoSuchConnectionException { // load connection, checking if it exists if (con == null) throw new IllegalArgumentException("connectionURI is not set"); if (message == null) throw new IllegalArgumentException("message is not set"); // construct chatMessage object to store in the db ChatMessage chatMessage = new ChatMessage(); chatMessage.setCreationDate(new Date()); chatMessage.setLocalConnectionURI(con.getConnectionURI()); chatMessage.setMessage(message); chatMessage.setOriginatorURI(con.getNeedURI()); // save in the db chatMessageRepository.saveAndFlush(chatMessage); return con; }