HHH-8683 EntityEntry backport on master

Hey @gunnarmorling and @sanne
I had to make a few adjustments to port it to master, can you double check it.
(new pull request on the correct repo)
I thought we don't really know if this one is the "best implementation possible", so I see no point in writing down exactly the thought process.
But adding a note on this being memory-intensive/sensitive would be useful, I'm not against that :)