|
From: Boyan T. (JIRA) <nh...@gm...> - 2011-05-19 06:40:59
|
[ http://216.121.112.228/browse/NH-2704?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=21126#action_21126 ]
Boyan Trushev commented on NH-2704:
-----------------------------------
I think we are in some sort of misunderstanding here...
So let me try to explain my idea with the example I gave in the test case from my first attachment. Let's have a Person entity which has one-to-one relation to an Employee:
<class name="Person">
<id name="Id" type="int">
<generator class="identity" />
</id>
<property name="Name"/>
<one-to-one name="Employee" lazy="proxy" property-ref="Person" fetch="select" />
</class>
public class Person
{
public virtual int Id { get; set; }
public virtual string Name { get; set; }
public virtual Employee Employee { get; set; }
}
When a person object is loaded from the database the following query is created:
SELECT
person0_.Id as Id0_0_,
person0_.Name as Name0_0_
FROM
Person person0_
WHERE
person0_.Id=@p0;
The Employee property should not be initialized on that stage. Now if the Employee property is accessed, the person proxy finds that the property is not initialized and produces a query like that to initialize it:
SELECT
employee0_.Id as Id1_0_,
employee0_.PersonName as PersonName1_0_,
employee0_.Person as Person1_0_
FROM
Employee employee0_
WHERE
employee0_.Person=@p0;
@p0 is the person id.
With the current NH version both queries are executed on loading of the person object - the Employee property is eagerly loaded. With the patch I proposed it works exactly as I described and IMHO this is the correct behavior. Hope it is now clear what I'm trying to explain and why I have opened the ticket.
> Bidirectional one-to-one relation through FK (using property-ref) proxiable
> ---------------------------------------------------------------------------
>
> Key: NH-2704
> URL: http://216.121.112.228/browse/NH-2704
> Project: NHibernate
> Issue Type: Improvement
> Components: Core
> Affects Versions: 3.2.0Alpha3
> Reporter: Boyan Trushev
> Priority: Minor
> Attachments: NH2704.patch, NH2704_fix.patch
>
>
> Hi,
> In our project we use one-to-one relations that are not referencing same primary key, instead property-ref is used to specify the referenced property. In this case however we have noticed that lazy="proxy" doesn't work as expected - the "lazy" objects are eagerly loaded on loading of the parent objec
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://216.121.112.228/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
|