This thread looks to be a little on the old side and therefore may no longer be relevant. Please see if there is a newer thread on the subject and ensure you're using the most recent build of any software if your question regards a particular product.
This thread has been locked and is no longer accepting new posts, if you have a question regarding this topic please email us at support@mindscape.co.nz
|
We have tables/entities associated by shared primary key defined as "primary key associations" by NHibernate reference: http://www.nhforge.org/doc/nh/en/index.html#mapping-declaration-onetoone We were initially using the one-to-one mapping for these entities but encountered performance problems. When selecting all entities with a one-to-one mapping to another we get single selects per entity against the other. Currently we have worked around the problem by using one-to-many mappings instead, but this gives suboptimal entity design. Is it possible to get better performance using one-to-one associations somehow? |
|
|
Perhaps I found an explanation: "Hibernates presents some peculiarity that, at first observance, doesn't make much sense. However, once you investigate the peculiarity thoroughly, you see why hibernate behaves the way it does. we see that an instance occurs when mapping a one-to-one relationship with a shared primary key. In certain instances, even if this mapping is declared to fetch lazily, hibernate will eagerly fetch the association. The reason is because due to the nature of a shared primary key, hibernate does not know whether to initialize the association to null or not without actually joining against the associated table." (found at https://forum.hibernate.org/viewtopic.php?t=969713) |
|
|
Hello Bjorn, Unfortunately we can't really provide support on the NHibernate runtime itself. As you've clearly found, the NHibernate forums and mailing lists will give you much better info than we can. Of course we are happy to improve the designer to make it generate the best possible mappings for your model -- however in this case it seems that the shared primary key pattern is inherently problematic and it doesn't sound like there's anything we could do in the generated mappings to improve that. Is that your understanding too? |
|
|
Agreed! |
|