Added code to avoid cross-products when querying entities with sub entities

Improved the methods in the DatabaseDao for querying objects from the database
with Hibernate so they do not return a cross product with identical records.
Some whitespace changes are also included.