Hibernate does that because it works with equals/hashCode when it comes to strings(varchar), which is always case sensitive. So the result of the query contains entities with identifiers `aaa`, `bbb` etc. and the foreign key value, by which Hibernate then tries to load objects for the associations, have the values `AAA`, `BBB` etc. For these values Hibernate can not find entities in the persistence context, so it will consult the database again. Unless you configured a case insensitive collation, the subsequent selects will produce no results. Overall, there is nothing Hibernate can do here. You will just have to fix your data. Also see the discussion with a user on Discourse that had a similar issue: https://discourse.hibernate.org/t/how-can-i-make-a-resultsetmapping-for-a-onetomany-only-happen-if-the-foreign-key-is-not-null/6567/7?u=beikov |