I have a simple Hibernate @ManyToOne mapping between two entities, using an association table thanks to annotation @JoinTable. Here is my mapping:
When I query on Customer entity, I always get an extra left join to the join table. For example, a HQL query such as SELECT c.id from Customer c generates the following SQL query:
I understand the left join is required when the full Customer entity is loaded, to know whether or not Address is null, but the LEFT JOIN seems totally useless in case of a projection, when just the id is selected in my example. This can be a performance issues for large tables.
Full source code to reproduce is available here: https://github.com/ndionisi/hibernate-extra-left-join
I reproduce it with Hibernate 5.1, 5.2 and 5.3.