Mon, 15 September 2014
How to Fix Duplicate Data from Hibernate QueriesThis problem was the bane of my existence when I first started using Hibernate because I had no idea where the problem was coming from. If you’re executing a query and finding that you have a bunch of duplicate records and haven’t a clue why, then you’re in the right place. You see the problem is typically caused by having left joins (or optional joins) in your objects. When you have a base object, like say Consider this scenario… A So what happens when you run a query that joins to the So because of this, Hibernate doesn’t massage the data for you, it just returns exactly what it got from the database. The ball is in your court to tell Hibernate what to do with records it has retrieved. There are two solutions to this problem:
|