Various fixes and improvements - especially PostgreSQL

 * various fixes, also for PostgreSQL
 * cast number to int
 * use correct sql statement for checking for albums
 * unit test for case when album is null
 * move casting to appframework entity
 * remove blank lines