diff --git a/src/main/java/musicplayer/db/DatabaseManager.java b/src/main/java/musicplayer/db/DatabaseManager.java index 976cd07..bf36c17 100644 --- a/src/main/java/musicplayer/db/DatabaseManager.java +++ b/src/main/java/musicplayer/db/DatabaseManager.java @@ -57,6 +57,7 @@ public class DatabaseManager { properties.put("hibernate.connection.driver_class", "org.hsqldb.jdbc.JDBCDriver"); properties.put("hibernate.connection.url", "jdbc:hsqldb:mem:."); properties.put("hibernate.hbm2ddl.auto", "create-drop"); + properties.put("hibernate.enable_lazy_load_no_trans", "true"); getInstance().sessionFactory = new Configuration() .addProperties(properties) .addAnnotatedClass(Album.class) diff --git a/src/main/java/musicplayer/db/Gateway.java b/src/main/java/musicplayer/db/Gateway.java index 071425e..7f3ce1f 100644 --- a/src/main/java/musicplayer/db/Gateway.java +++ b/src/main/java/musicplayer/db/Gateway.java @@ -7,6 +7,7 @@ import org.hibernate.Session; import org.hibernate.criterion.Restrictions; import java.io.File; +import java.util.ArrayList; import java.util.List; import java.util.Map; import java.util.Optional; @@ -70,9 +71,8 @@ public class Gateway { * @return All songs currently in the database, grouped by album. */ public static Optional>> listAllSongsGroupedByAlbum() { - Optional> songList = listAllT(Song.class); - return (songList.isPresent()) ? - Optional.of(songList.get().stream().collect(Collectors.groupingBy(Song::getAlbum))) + Optional> albumList = listAllT(Album.class); + return (albumList.isPresent()) ? Optional.of(albumList.get().stream().collect(Collectors.toMap(x -> x, x -> new ArrayList<>(x.getSongs())))) : Optional.empty(); } @@ -80,9 +80,8 @@ public class Gateway { * @return All songs currently in the database, grouped by artist. */ public static Optional>> listAllSongsGroupedByArtist() { - Optional> songList = listAllT(Song.class); - return (songList.isPresent()) ? - Optional.of(songList.get().stream().collect(Collectors.groupingBy(Song::getArtist))) + Optional> artistListList = listAllT(Artist.class); + return (artistListList.isPresent()) ? Optional.of(artistListList.get().stream().collect(Collectors.toMap(x -> x, x -> new ArrayList<>(x.getSongs())))) : Optional.empty(); }