From 6344e9dbe9e12b2b738044c2a89bc9a4582c62bc Mon Sep 17 00:00:00 2001 From: Nathan Cannon Date: Wed, 10 Feb 2016 23:20:51 +0000 Subject: [PATCH] Fixed album/artist cascading on song creation and null album art detection. --- src/main/java/musicplayer/db/Gateway.java | 2 -- src/main/java/musicplayer/model/ExtractedMetadata.java | 2 +- src/main/java/musicplayer/model/Song.java | 4 ++-- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/src/main/java/musicplayer/db/Gateway.java b/src/main/java/musicplayer/db/Gateway.java index d8f52ec..10f3cfb 100644 --- a/src/main/java/musicplayer/db/Gateway.java +++ b/src/main/java/musicplayer/db/Gateway.java @@ -75,13 +75,11 @@ public class Gateway { if (!albumObj.isPresent()) { Album album = new Album(metadata.album, metadata.artwork); albumObj = Optional.of(album); - session.save(album); } Optional artistObj = getOneArtist(metadata.artist); if (!artistObj.isPresent()) { Artist artist = new Artist(metadata.artist); artistObj = Optional.of(artist); - session.save(artist); } session.save(new Song(metadata.trackNumber, metadata.title, artistObj.get(), albumObj.get(), metadata.genre, metadata.songFile)); session.getTransaction().commit(); diff --git a/src/main/java/musicplayer/model/ExtractedMetadata.java b/src/main/java/musicplayer/model/ExtractedMetadata.java index 189586b..95c6ade 100644 --- a/src/main/java/musicplayer/model/ExtractedMetadata.java +++ b/src/main/java/musicplayer/model/ExtractedMetadata.java @@ -49,7 +49,7 @@ public class ExtractedMetadata { Image actualImage = ImageIO.read(imageFile.get().toFile()); tmpArt = convertImageToBytes(actualImage); } - } catch (IOException ignored) {} + } catch (NullPointerException | IOException ignored) {} } artwork = tmpArt; } diff --git a/src/main/java/musicplayer/model/Song.java b/src/main/java/musicplayer/model/Song.java index d4871d5..f84af65 100644 --- a/src/main/java/musicplayer/model/Song.java +++ b/src/main/java/musicplayer/model/Song.java @@ -19,13 +19,13 @@ public class Song implements Comparable { @GeneratedValue(strategy = GenerationType.AUTO) @Column(name = "id") private long id; - @ManyToOne + @ManyToOne(cascade = CascadeType.ALL) private Artist artist; @Column(name = "genre") private String genre; @Column(name = "title") private String title; - @ManyToOne + @ManyToOne(cascade = CascadeType.ALL) private Album album; @Column(name = "songFile") private String songFile;