TL;DR:
It depends
Efficiency is not subjective, but it is a question of definition and context.
You need to consider what efficiency really is.
Do you only consider the efficiency at runtime?
Or is the efficiency at development time relevant?
Is efficiency for you the same as performance/speed?
Or is the load on the database server relevant?
In most cases for most projects the development time is actually more relevant. Most code is not on a hot execution path, so as long as the performance is not horrible it doesn't matter that much.
But we typically only talk about the cases where runtime efficiency actually does matter, either because our servers get under heavy load or because response times aren't satisfying.
So once you know what you actually want and need you can start measuring/estimating the two approaches. Again how much effort you put in these depends on how much you might gain from an improvement.
When measuring make sure you measure in realistic environments, this includes that other queries that get typically get executed in the same or parallel threads not to be considered as well.
With all that said:
On their own, the dedicated select statement will be faster and consume less resources on the db server, network and on your application server for the following reasons:
- less data has to be selected, with a good chance that data can be loaded from indexes instead of accessing tables, which will probably necessary for materializing a two full objects.
- less data has to be transferred over the wire.
- Instead of constructing two full objects only one primitive has to get constructed. Since in setting each attribute there is possibly a conversion and creation of intermediate objects involved, this can be a significant difference.
But in an actual application it is perfectly possible that accessing the post and the user will be satisfied from the 1st level cache, i.e. the objects are already loaded into the EntityManager
and are already fully materialised. In this case the dedicated SQL statement will be much less efficient by all reasonable metrics.