Hello everyone.
I'm using NHibernate 2.0. I am having some problems when eagerly fetching some data from an "association entity" with a composite-id.
The mapping file looks like this:
Code:
<class name="AssociationEntity">
<composite-id>
<key-many-to-one name="Entity1" column="Entity1Id" />
<key-many-to-one name="Entity2" column="Entity2Id" />
</composite-id>
<!-- other properties -->
</class>
I'd like to fetch a list of those entities using HQL, while eagerly fetching one of the two keys in the composite-id (via join). The HQL query I'm using is the following:
Code:
FROM AssociationEntity AS ae
LEFT JOIN FETCH ae.Entity1
ORDER BY ...
The resulting SQL query is correct, but NHibernat will ignore the data that has already been fetched and query for all the referenced entities again.
After the first query is executed (with the join), the log contains lines like:
Code:
initializing proxy: [Entity1...]
attempting to resolve: [Entity1...]
object not resolved in any cache: [Entity1...]
Fetching entity [Entitiy1...]
...
But, if two instances of AssociationEntity contain a reference to the same Entitiy1 instance, the value will correctly be found in the session cache. But this should already be the case for every single AssociationEntity instance, since all needed data was already loaded during the first HQL query... Am I doing something wrong somewhere?