I posted this topic on the Fluent NH group and am looking how to
accomplish this with a straight XML mapping.
http://groups.google.com/group/fluent-nhibernate/browse_thread/thread/62e5f89c451cea85/d8dd0f42fdc6449e#d8dd0f42fdc6449e
The situation is this. I have 2 tables, Policy and CrdtCrdAcct. A
policy can have many CreditCard records. The problem is that the keys
don't match up. In addition, there is no FK between these two tables.
I have NO control over the DB and cannot change it.
The PK of Policy is:
- Policy_Number
-PolicyDateTime
The PK of CreditCardAccount is:
- Pol_Nbr
- CCNum
- CCType
- CCEXP
- (2 other columns)
I want to have my Policy have a collection of CreditCard records and I
want those records to be linked to Policy by PolicyNumber. I've tried
to use property-ref, but I'm running into a problem because
Policy.PolicyNumber is part of the composite key and not a property.
So I tried to fake it out by adding a property PolicyNumberMapping
with Access=none, but I get an index out of range exception because I
have 2 props pointing at the same column. Below is the relevant
mappings I have so far for Policy and CreditCardAccount. Any guidance
would be greatly appreciated.
----------------------------------
POLICY
---------------------------------
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" default-
access="property" auto-import="true" default-cascade="none" default-
lazy="true">
<class xmlns="urn:nhibernate-mapping-2.2" mutable="true"
name="NHibernate.Spike.Data.Entities.PolicyRecord,
NHibernate.Spike.Data, Version=1.0.0.0, Culture=neutral,
PublicKeyToken=null" table="POLICY">
<composite-id mapped="false" unsaved-value="undefined">
<key-property name="PolicyNumber" type="System.String, mscorlib,
Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<column name="`POLICY_NUMBER`" />
</key-property>
<key-property name="PolicyDateTime" type="System.Nullable`1
[[System.DateTime, mscorlib, Version=2.0.0.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089]], mscorlib, Version=2.0.0.0,
Culture=neutral, PublicKeyToken=b77a5c561934e089">
<column name="`POLICY_DATE_TIME`" />
</key-property>
</composite-id>
<property access="none" name="PolicyNumberMapping"
type="System.String, mscorlib, Version=2.0.0.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089">
<column name="`POLICY_NUMBER`" />
</property>
<bag cascade="save-update" name="CreditCards" mutable="true">
<key property-ref="PolicyNumberMapping">
<column name="`POL_NBR`" />
</key>
<one-to-many class="Aah.Policy.InfoLayer.CrdtCardAcctRecord,
NHibernate.Spike.Data, Version=1.0.0.0, Culture=neutral,
PublicKeyToken=null" />
</bag>
</class>
</hibernate-mapping>
-----------------------------
CreditCardAccount
----------------------------
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" default-
access="property" auto-import="true" default-cascade="none" default-
lazy="true">
<class xmlns="urn:nhibernate-mapping-2.2" mutable="true"
name="Aah.Policy.InfoLayer.CrdtCardAcctRecord, NHibernate.Spike.Data,
Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"
table="CRDT_CARD_ACCT">
<composite-id mapped="false" unsaved-value="undefined">
<key-property name="PolNbr" type="System.String, mscorlib,
Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<column name="`POL_NBR`" />
</key-property>
<key-property name="CrdtCardNbr" type="System.String, mscorlib,
Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<column name="`CrdtCardNbr`" />
</key-property>
<key-property name="ExpDt" type="System.Nullable`1
[[System.DateTime, mscorlib, Version=2.0.0.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089]], mscorlib, Version=2.0.0.0,
Culture=neutral, PublicKeyToken=b77a5c561934e089">
<column name="`ExpDt`" />
</key-property>
<key-property name="CrdtCardTypeCd" type="System.String,
mscorlib, Version=2.0.0.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089">
<column name="`CrdtCardTypeCd`" />
</key-property>
<key-property name="AcctId" type="System.String, mscorlib,
Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<column name="`AcctId`" />
</key-property>
<key-property name="PolTypeCd" type="System.String, mscorlib,
Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<column name="`PolTypeCd`" />
</key-property>
</composite-id>
<property name="VaultLastPymntDt" type="System.Nullable`1
[[System.DateTime, mscorlib, Version=2.0.0.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089]], mscorlib, Version=2.0.0.0,
Culture=neutral, PublicKeyToken=b77a5c561934e089">
<column name="`VAULT_LAST_PYMNT_DT`" />
</property>
</class>
</hibernate-mapping>
-----------------------
ERROR
-----------------------
Test method
NHibernate.Spike.Test.Unit.Mappings.When_policy_is_mapped.Can_map_policy
threw exception: System.ArgumentOutOfRangeException: Index was out of
range. Must be non-negative and less than the size of the collection.
Parameter name: index.
at System.ThrowHelper.ThrowArgumentOutOfRangeException
(ExceptionArgument argument, ExceptionResource resource)
at System.ThrowHelper.ThrowArgumentOutOfRangeException()
at System.Collections.Generic.List`1.get_Item(Int32 index)
at System.Data.SQLite.SQLiteParameterCollection.GetParameter(Int32
index)
at
System.Data.Common.DbParameterCollection.System.Collections.IList.get_Item
(Int32 index)
at NHibernate.Type.DateTimeType.Set(IDbCommand st, Object value, Int32
index)
at NHibernate.Type.NullableType.NullSafeSet(IDbCommand cmd, Object
value, Int32 index)
at NHibernate.Type.NullableType.NullSafeSet(IDbCommand st, Object
value, Int32 index, ISessionImplementor session)
at NHibernate.Type.ComponentType.NullSafeSet(IDbCommand st, Object
value, Int32 begin, ISessionImplementor session)
at NHibernate.Persister.Entity.AbstractEntityPersister.Dehydrate
(Object id, Object[] fields, Object rowId, Boolean[] includeProperty,
Boolean[][] includeColumns, Int32 table, IDbCommand statement,
ISessionImplementor session, Int32 index)
at NHibernate.Persister.Entity.AbstractEntityPersister.Insert(Object
id, Object[] fields, Boolean[] notNull, Int32 j, SqlCommandInfo sql,
Object obj, ISessionImplementor session)
at NHibernate.Persister.Entity.AbstractEntityPersister.Insert(Object
id, Object[] fields, Object obj, ISessionImplementor session)
at NHibernate.Action.EntityInsertAction.Execute()
at NHibernate.Engine.ActionQueue.Execute(IExecutable executable)
at NHibernate.Engine.ActionQueue.ExecuteActions(IList list)
at NHibernate.Engine.ActionQueue.ExecuteActions()
at
NHibernate.Event.Default.AbstractFlushingEventListener.PerformExecutions
(IEventSource session)
at NHibernate.Event.Default.DefaultFlushEventListener.OnFlush
(FlushEvent event)
at NHibernate.Impl.SessionImpl.Flush()
at NHibernate.Transaction.AdoTransaction.Commit()
at
NHibernate.Spike.Test.Unit.Mappings.When_policy_is_mapped.Can_map_policy
() in
--
You received this message because you are subscribed to the Google Groups
"nhusers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/nhusers?hl=en.