[hibernate-issues] [Hibernate-JIRA] Created: (HHH-3653) Allow lazy loading for one-to-one association when constrained="false"

Eric Sirianni (JIRA) noreply at atlassian.com
Fri Dec 12 11:45:39 EST 2008


Allow lazy loading for one-to-one association when constrained="false"
----------------------------------------------------------------------

                 Key: HHH-3653
                 URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-3653
             Project: Hibernate Core
          Issue Type: Improvement
          Components: core
    Affects Versions: 3.3.1
            Reporter: Eric Sirianni


Hibernate currently has a documented restriction on one-to-one associations that prohibits lazy loading when constrained="false"

lazy (optional - defaults to proxy): By default, single point associations are proxied. lazy="no-proxy" specifies that the property should be fetched lazily when the instance variable is first accessed (requires build-time bytecode instrumentation). lazy="false" specifies that the association will always be eagerly fetched. Note that if constrained="false", proxying is impossible and Hibernate will eager fetch the association! 

The rationale for this seems to be that
 - If constrained="false", then hibernate has to execute a SELECT on the associated table in order to set the parent's reference to NULL vs. a child proxy
 - Since hibernate has to do this SELECT anyway, then why not just load the actual child record instead of the proxy

This is summarized in http://www.hibernate.org/162.html:
  "But a SELECT to check presence is just inefficient because the same SELECT may not just check presence, but load entire object. So lazy loading goes away."

The notes on that page do a good job explaining the flaw in this rationale:

---
This is hugely wrong.  Imagine a table with a FK and a 20M blob of data
in each row.  Lazy loading the blob when displaying a list of rows for
example is useful, even if you have to select the PK column to find out
the rows exist.  Lazy loading has more uses than avoiding the SQL
execution.  In this case avoiding the memory overhead of creating
perhaps hundreds of M of data in memory when it's not needed.

---
I have a one-to-one where the foreign table is very large and
holds a bunch of infrequently used information. Most parent records do
not need a detail record as they do not have any of the information it
stores. Parent records are cached and heavily used. It would be a waste
to fill up memory  or table space with mostly unused detail records.

---
My project is in the exact same situation.  We have one-to-one records where the child objects have a significant amount of details (CLOBs) that take up a lot of space in memory.  We would like these to be lazy loaded.  

Please consider this feature request.  I don't think the implementation would be very difficult.  It would be straight forward to add a join on the id column of the
foreign table. That would permit Hibernate to discover whether an optional one-to-one object was present and have enough info to create the proxy vs. the NULL reference.

-- 
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