I am having a performance issue in my SQL using Hibernate DetachedCriteria. I have several one-two-one relationships, and when Hibernate generates SQL, it includes all the fields from the tables that are combined in FROM. When this happens, it takes MySQL a long time to run the query (which also has order and an additional query, adding to the problem). For my 50K records - 6 sec. When I delete unnecessary fields in SELECT only for the domain object I'm worried about, it works for up to 500 ms.
Is there a way by which Hibernate can not include fields from joins?
I tried setting the fetch parameter in the mapping files to "join" and "select", and it has no meaning in the generated SQL.
I also tried to set a separate root entry, but from what I read, this does not work with paging (which I also do).
I could try and write the query as HQL, but with a subquery it just increases the headache.
source share