views:

911

answers:

2

Mapping a dictionary with NH. Declaration is as follows:

<hibernate-mapping ...
    <map 
     name="CostsByRole" 
     table="JobAccountingSnapshotCosts"
     lazy="false" 
     fetch="join" 
     access="nosetter.camelcase-underscore">
      <key column="SnapshotId" />
      <index column="RoleCode" type="String" />
      <element column="Amount" type="Decimal" />
    </map>
</hibernate-mapping>

I am expecting a single SQL query to be generated but instead I get two: a select for the actual object, followed by a select for the contents of the dictionary.

Any ideas?

+1  A: 

Assuming it's not a typo on submission, the problem is likely to be the join="fetch" part in your mapping. It should be fetch="join" and since the default for fetch is "select", that would yield your sequential select problem.

Stuart Childs
Indeed, it was a typo (thank you for catching that!), now corrected.
Michael Teper
+2  A: 

HQL queries do not consider the values set for fetch in the mapping. You need to specify them exclusively in each HQL query. Its supposedly by design. The fetch attributes value is used only by Criteria queries and by Load/Get.

Amith George