From: Boyan T. (JIRA) <nh...@gm...> - 2011-05-13 11:13:00
|
Lazy="proxy" does eager load on one-to-one relation using property-ref ---------------------------------------------------------------------- Key: NH-2704 URL: http://216.121.112.228/browse/NH-2704 Project: NHibernate Issue Type: Bug Components: Core Affects Versions: 3.2.0Alpha3 Reporter: Boyan Trushev Priority: Minor 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 |
From: Boyan T. (JIRA) <nh...@gm...> - 2011-05-13 11:54:00
|
[ http://216.121.112.228/browse/NH-2704?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ] Boyan Trushev updated NH-2704: ------------------------------ Attachment: NH2704.patch a patch with a test case to demonstrate the issue > Lazy="proxy" does eager load on one-to-one relation using property-ref > ---------------------------------------------------------------------- > > Key: NH-2704 > URL: http://216.121.112.228/browse/NH-2704 > Project: NHibernate > Issue Type: Bug > Components: Core > Affects Versions: 3.2.0Alpha3 > Reporter: Boyan Trushev > Priority: Minor > Attachments: NH2704.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 |
From: Boyan T. (JIRA) <nh...@gm...> - 2011-05-13 12:12:01
|
[ http://216.121.112.228/browse/NH-2704?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ] Boyan Trushev updated NH-2704: ------------------------------ Attachment: NH2704_fix.patch It seems only changing of islazyProperty assignment in EntityMetamodel to include also the one-to-one properties with lazy="proxy" solves the problem. The patch contains the proposed solution. > Lazy="proxy" does eager load on one-to-one relation using property-ref > ---------------------------------------------------------------------- > > Key: NH-2704 > URL: http://216.121.112.228/browse/NH-2704 > Project: NHibernate > Issue Type: Bug > 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 |
From: Fabio M. (JIRA) <nh...@gm...> - 2011-05-13 16:12:01
|
[ http://216.121.112.228/browse/NH-2704?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ] Fabio Maulo updated NH-2704: ---------------------------- Issue Type: Improvement (was: Bug) Summary: Bidirectional one-to-one relation through FK (using property-ref) proxiable (was: Lazy="proxy" does eager load on one-to-one relation using property-ref) The current behavior is expected due to the relation to a property that is not the PK. NH have to hit the DB to know the value of the property holding the relation, hitting it he can initialize the object. In practice the one-to-one through FK is not a real one-to-one and it can be transformed to a one-to-many easily. The real one-to-one is through PK. > 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 |
From: Boyan T. (JIRA) <nh...@gm...> - 2011-05-16 06:22:47
|
[ http://216.121.112.228/browse/NH-2704?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=21081#action_21081 ] Boyan Trushev commented on NH-2704: ----------------------------------- Hi Fabio, Thanks for the quick reply! >NH have to hit the DB to know the value of the property holding the relation, hitting it he can initialize the object. Why should NH hit the DB to know the value of the property? Couldn't this be done on accessing of the "lazy" property? The object containing the property is a proxy and it could check that the property is still not initialized and then hit the DB. That's exactly what I achieved with the patch I proposed in my previous comment. Have you had a look at it? >In practice the one-to-one through FK is not a real one-to-one and it can be transformed to a one-to-many easily. The real one-to-one is through PK. In our current project we use POCOs and for one-to-one relation there is a single property to hold the relation, it cannot be easily transformed to one-to-many as for one-to-many we will need a list rather than just a property - which is unacceptable in our case. > 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 |
From: Fabio M. (JIRA) <nh...@gm...> - 2011-05-18 14:30:56
|
[ http://216.121.112.228/browse/NH-2704?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=21117#action_21117 ] Fabio Maulo commented on NH-2704: --------------------------------- In the proxy you have the ID of the PK of the other object, not the value representing the relation (the property-ref has that value). > 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 |
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 |