diff --git a/libresonic-main/src/main/java/org/libresonic/player/dao/PlayerDao.java b/libresonic-main/src/main/java/org/libresonic/player/dao/PlayerDao.java index 7c37d533..37d9f6a4 100644 --- a/libresonic-main/src/main/java/org/libresonic/player/dao/PlayerDao.java +++ b/libresonic-main/src/main/java/org/libresonic/player/dao/PlayerDao.java @@ -86,7 +86,11 @@ public class PlayerDao extends AbstractDao { * @param player The player to create. */ public synchronized void createPlayer(Player player) { - int id = getJdbcTemplate().queryForObject("select max(id) from player", Integer.class) + 1; + Integer existingMax = getJdbcTemplate().queryForObject("select max(id) from player", Integer.class); + if(existingMax == null) { + existingMax = 0; + } + int id = existingMax + 1; player.setId(String.valueOf(id)); String sql = "insert into player (" + COLUMNS + ") values (" + questionMarks(COLUMNS) + ")"; update(sql, player.getId(), player.getName(), player.getType(), player.getUsername(), diff --git a/libresonic-main/src/main/java/org/libresonic/player/dao/TranscodingDao.java b/libresonic-main/src/main/java/org/libresonic/player/dao/TranscodingDao.java index 5ca8a3e9..d3d11720 100644 --- a/libresonic-main/src/main/java/org/libresonic/player/dao/TranscodingDao.java +++ b/libresonic-main/src/main/java/org/libresonic/player/dao/TranscodingDao.java @@ -82,8 +82,11 @@ public class TranscodingDao extends AbstractDao { * @param transcoding The transcoding to create. */ public synchronized void createTranscoding(Transcoding transcoding) { - int id = getJdbcTemplate().queryForObject("select max(id) + 1 from transcoding2", Integer.class); - transcoding.setId(id); + Integer existingMax = getJdbcTemplate().queryForObject("select max(id) from transcoding2", Integer.class); + if(existingMax == null) { + existingMax = 0; + } + transcoding.setId(existingMax + 1); String sql = "insert into transcoding2 (" + COLUMNS + ") values (" + questionMarks(COLUMNS) + ")"; update(sql, transcoding.getId(), transcoding.getName(), transcoding.getSourceFormats(), transcoding.getTargetFormat(), transcoding.getStep1(),