I've prepared a reproducer in a repository on github:
I don't understand hibernate internals enough to dig deeper, but this is clearly unwanted, because when I've just enabled it on our project, one of my API endpoints went from 10 queries to 816 queries and I gave up on examining the rest of them.
I've even tried to annotated all of toOne relations in our project with different combinations of @LazyToOne (with different LazyToOneOption) and @LazyGroup in the hopes that I've just misunderstood the feature, but it just went from broken (because of 100x times more queries which is unacceptable) to completely broken (where the data weren't even loading properly).
java version "1.8.0_191"
Java(TM) SE Runtime Environment (build 1.8.0_191-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.191-b12, mixed mode)
You might be interested in this issue.
It looks very similar to https://hibernate.atlassian.net/browse/HHH-12298 .
The application code is:
The elements are marked as lazy but JOIN FETCH is used, the generated query is properly including them in a join but apparently individual SELECT queries are also generated.
What is really weird is that we don't even try to load the data as we only access products.size().
It looks as if the data were loaded twice, once with a JOIN and the second time with subsequent selects.
, the many-to-one associations in your test entities need to be annotated with @LazyToOne(LazyToOneOption.NO_PROXY).
I believe that the extra queries you are seeing are due to Hibernate eagerly loading Product.name.previousName and Product.description.previousDescription.
Without bytecode enhancement, Hibernate would have created uninitialized proxies for those associations. Because proxies are incompatible with bytecode enhancement, hibernate eagerly loads these associations.
I've copied your entities into a unit test and added the @LazyToOne(LazyToOneOption.NO_PROXY). Now there is only the requested query that gets executed. You can see the modified test at https://github.com/gbadner/hibernate-core/tree/HHH-13134-test.
Please give this a try and let us know if that works for you.