[hibernate-issues] [Hibernate-JIRA] Created: (HHH-2073) many-to-one join fetch with optional parent causing stray query to fire

Adam Hardy (JIRA) noreply at atlassian.com
Wed Sep 13 06:54:25 EDT 2006


many-to-one join fetch with optional parent causing stray query to fire
-----------------------------------------------------------------------

         Key: HHH-2073
         URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-2073
     Project: Hibernate3
        Type: Bug

    Reporter: Adam Hardy
    Priority: Minor
 Attachments: bugtest.zip

I have a call centre application which uses a mature database and is therefore pushing Hibernate to accomplish the mappings I need. The issue here is extra queries that Hibernate is firing where I set up the mapping to do a join in one hit. 

I am fetching child objects which may or may not have a parent. The child's foreign key points to a non-primary key on the parent. This is not reflected by a foreign key constraint in the database (hence it allows child to have no parent). 

If the child object has the foreign key 0 instead of null, which is the protocol in this database, then the parent which doesn't exist is not (& cannot) be instantiated, no problem, but then after processing the resultset, Hibernate fires off another query to fetch the parent that it could not find data for in the first query. 

This is obviously unnecessary in this context and degrades the performance on large searches on this child. 

I have classified it as minor since I suspect there may be work-arounds but I have not researched that yet. 

I didn't know whether I could put the mapping XML in the query, so I have attached a simplistic testcase example that demonstrates the problem. 

The following forum messages are relevant and the latter contains the mappings, which is easier than extracting them out of the testcase zip:

http://forum.hibernate.org/viewtopic.php?t=960522

http://forum.hibernate.org/viewtopic.php?t=964211




-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://opensource.atlassian.com/projects/hibernate/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira




More information about the hibernate-issues mailing list