Fixed album/artist cascading on song creation and null album art detection.

This commit is contained in:
neviyn 2016-02-10 23:20:51 +00:00
parent 005e116505
commit 6344e9dbe9
3 changed files with 3 additions and 5 deletions

View File

@ -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<Artist> 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();

View File

@ -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;
}

View File

@ -19,13 +19,13 @@ public class Song implements Comparable<Song> {
@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;