many-to-one mapping with composite-id formula fails
Description
Environment
Attachments
Activity

Fabio Maulo July 20, 2010 at 9:39 AM
Formula and Column should work in exclusion; all formulas or all columns, you shouldn't mix the behavior.

Julian Maughan July 20, 2010 at 2:22 AM
Committed to trunk (revision 5017). Will commit Binder refactoring separately, later.

Julian Maughan July 19, 2010 at 8:43 AM
As I mentioned previously, I don't think this issue should be regarded as a Bug, so I'm changing it to an Improvement.

Julian Maughan June 20, 2010 at 7:51 PM
Attachments: 1) Proposed solution [NH-2117.JM.patch], 2) An updated unit-test [NH-2117.JM.test.patch], 3) Binder refactor [Replace Binder static with instance methods.patch].
Implementation details:
a) NH-only classes:
ValuePropertyBinder - added support for column+formula many-to-one mappings.
ColumnBinder - added overload to support changes in ValuePropertyBinder. Removed assignment of column index. This is redundant as it is performed by SimpleValue when columns are added.
nhibernate-mapping.xsd - Updated many-to-one element, allowing column+formula mappings
HbmManyToOne - Added ColumnsAndFormulas property as ValuePropertyBinder needs the combined many-to-one column+formula mappings in declared order.
ClassCompositeIdBinder - Set Component.IsKey property to true so that ComponentType.ResolveIdentifier does not instantiate the composite ID class if any of the key values are null.
b) Hibernate classes:
ANSIJoinFragment - Encountered bug. Fixed as per Hibernate code-base
SelectFragment - Encountered bug. Fixed as per Hibernate code-base
All tests pass on trunk revision 4985 (HEAD has failing tests due to other work that is going on).
@sthomas: Not sure your issue is the same as the one reported by Richard. I suggest raising a separate Issue for it, and I will do a bit of investigation.

sthomas June 15, 2010 at 10:32 PM
Sorry again for correcting that last example one more time (it's late...):
<many-to-one name="Car" class="Car">
<formula>
'(select c.ID1 from CAR c where c.ID1=CAR_ID1)'
</formula>
<formula>
'(select c.ID2 from CAR c where c.ID2=CAR_ID2)'
</formula>
</many-to-one>
Details
Details
Assignee

Reporter

When using a many-to-one with a composite-id and formula, such as:
<many-to-one name="ShippingAddress">
<column name="ShippingAddressId"/>
<formula>'SHIPPING'</formula>
</many-to-one>
NHibernate fails with:
NHibernate.MappingException : property mapping has wrong number of columns:
This behavior is supported by Hibernate.
See:
http://anonsvn.jboss.org/repos/hibernate/core/trunk/testsuite/src/test/java/org/hibernate/test/typedmanytoone/Customer.hbm.xml
There is a potentially related bug in Hibernate Jira:
http://opensource.atlassian.com/projects/hibernate/browse/HHH-2086