Hi,

I'm stuck with this mapping, hope someone can help me with this.

I have the next graph (part of)

    [ActiveRecord("Insurance"), JoinedBase]
    public class BaseInsurance
    {
    }

    [ActiveRecord]
    public class IndividualInsurance : BaseInsurance
    {
        [JoinedKey]
        public int Id { get; set; }

        public InsuredItem InsuredItem
        {
            get
            {
                return (_Movs == null || _Movs.Count == 0? null : _Movs
[0]);
            }
            set
            {
                if (_Movs == null)
                {
                    _Movs = new List<BienAsegurado>();
                    _Movs.Add(value);
                }
                _Movs[0] = value;
            }
        }

        [HasMany(ColumnKey = "Insurance", Cascade =
ManyRelationCascadeEnum.All,
            Lazy = false, Table = "InsuredItem", Index =
"IndividualInsuredItem")]
        protected IList<InsuredItem> _Movs { get; set; }

    }

    [ActiveRecord]
    public class PoolInsurance : BaseInsurance
    {
        [JoinedKey]
        public int Id { get; set; }

        [HasMany(ColumnKey = "Insurance", Cascade =
ManyRelationCascadeEnum.All,
            Lazy = false, Table = "InsuredItem", Index =
"PoolInsuredItem")]
        public IList<BienAsegurado> Movimientos { get; set; }

    }

I need to do this because an IndividualInsurance can have one and only
one InsuredItem, but PoolInsurance can have many (10, 100, 100 items),
i need to save the insured items on the same table, but when starting
my test active record throws this error:



Castle.ActiveRecord.Framework.Scopes.ScopeMachineryException: Tried to
unregister a scope that is not the active one

en
Castle.ActiveRecord.Framework.Scopes.AbstractThreadScopeInfo.UnRegisterScope
(ISessionScope scope) en c:\Users\TrentCioran\Desktop\Tools\castle
\ActiveRecord\Castle.ActiveRecord\Framework\Scopes
\AbstractThreadScopeInfo.cs: line 67
en
Castle.ActiveRecord.Framework.Scopes.ThreadScopeAccessor.UnRegisterScope
(ISessionScope scope) en c:\Users\TrentCioran\Desktop\Tools\castle
\ActiveRecord\Castle.ActiveRecord\Framework\Scopes
\ThreadScopeAccessor.cs: line 95
en Castle.ActiveRecord.Framework.Scopes.AbstractScope.Dispose() en c:
\Users\TrentCioran\Desktop\Tools\castle\ActiveRecord
\Castle.ActiveRecord\Framework\Scopes\AbstractScope.cs: line 177
en Cognitum.Aplication.Test.AbstractTestCase.DisposeScope() en
AbstractTestCase.cs: line 55
en Cognitum.Aplication.Test.AbstractTestCase.Terminate() en
AbstractTestCase.cs: line 32

System.Data.SqlClient.SqlException: The UPDATE statement conflicted
with the FOREIGN KEY constraint "FKD7DA67478FEFF4E1". The conflict
occurred in database "Cognitum", table "dbo. PoolInsurance ", column
'Id'.

The statement has been terminated.
en System.Data.SqlClient.SqlConnection.OnError(SqlException exception,
Boolean breakConnection)
en System.Data.SqlClient.SqlInternalConnection.OnError(SqlException
exception, Boolean breakConnection)
en System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning
(TdsParserStateObject stateObj)
en System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior,
SqlCommand cmdHandler, SqlDataReader dataStream,
BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject
stateObj)
en System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader
ds, RunBehavior runBehavior, String resetOptionsString)
en System.Data.SqlClient.SqlCommand.RunExecuteReaderTds
(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean
returnStream, Boolean async)
en System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior
cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String
method, DbAsyncResult result)
en System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery
(DbAsyncResult result, String methodName, Boolean sendToPipe)
en System.Data.SqlClient.SqlCommand.ExecuteNonQuery()
en NHibernate.AdoNet.AbstractBatcher.ExecuteNonQuery(IDbCommand cmd)
en NHibernate.AdoNet.NonBatchingBatcher.AddToBatch(IExpectation
expectation)
en
NHibernate.Persister.Collection.AbstractCollectionPersister.PerformInsert
(Object ownerId, IPersistentCollection collection, IExpectation
expectation, Object entry, Int32 index, Boolean useBatch, Boolean
collable, ISessionImplementor session)
en NHibernate.Persister.Collection.AbstractCollectionPersister.Recreate
(IPersistentCollection collection, Object id, ISessionImplementor
session)
NHibernate.Exceptions.GenericADOException: could not insert
collection: [Cognitum.Dominio.Polizas.PolizaIndividual._Movs#1][SQL:
SQL not available]
en NHibernate.Persister.Collection.AbstractCollectionPersister.Recreate
(IPersistentCollection collection, Object id, ISessionImplementor
session)
en NHibernate.Action.CollectionRecreateAction.Execute()
en NHibernate.Engine.ActionQueue.Execute(IExecutable executable)
en NHibernate.Engine.ActionQueue.ExecuteActions(IList list)
en NHibernate.Engine.ActionQueue.ExecuteActions()
en
NHibernate.Event.Default.AbstractFlushingEventListener.PerformExecutions
(IEventSource session)
en NHibernate.Event.Default.DefaultFlushEventListener.OnFlush
(FlushEvent event)
en NHibernate.Impl.SessionImpl.Flush()
en Castle.ActiveRecord.Framework.Scopes.AbstractScope.PerformDisposal
(ICollection`1 sessions, Boolean flush, Boolean close) en c:\Users
\TrentCioran\Desktop\Tools\castle\ActiveRecord\Castle.ActiveRecord
\Framework\Scopes\AbstractScope.cs: line 208
en Castle.ActiveRecord.SessionScope.PerformDisposal(ICollection`1
sessions) en c:\Users\TrentCioran\Desktop\Tools\castle\ActiveRecord
\Castle.ActiveRecord\Framework\Scopes\SessionScope.cs: line 85
en Castle.ActiveRecord.Framework.Scopes.AbstractScope.Dispose() en c:
\Users\TrentCioran\Desktop\Tools\castle\ActiveRecord
\Castle.ActiveRecord\Framework\Scopes\AbstractScope.cs: line 179
en Cognitum.Aplication.Test.AbstractTestCase.DisposeScope() en
AbstractTestCase.cs: line 55
en Cognitum.Aplication.Test.AbstractTestCase.FlushAndRecreateScope()
en AbstractTestCase.cs: line 44
en
Cognitum.Aplication.Test.Insurance.Repository.PoolInsuranceRepositoryFixture.Update
() en PoolInsuranceRepositoryFixture.cs: line 99



It seems that there is a conflict between the two collections, the one
from IndividualInsurance and the PoolInsurance.

Am I doing it wrong?


Suggestions?


Thanks
TrentCioran


P.S. So sorry for my poor english =P
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Castle Project Users" 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/castle-project-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to