Hi there, 
        
The issue AR-ISSUE-260 was just created by Thiago (Serenus).
        
        Key: AR-ISSUE-260
        Summary: Single Table Inheritance issue, HasMany Relationship, 
Discriminator not displayed in SQL Statement
        Type: Bug
        Importance: Medium
        
        Description:
        Bug Description:
When using a HasMany relationship to an object collection that is based off a 
Single Table Inheritance, the discriminator is not being included in the SQL 
statement, so it's returning all parent objects instead of only the specified 
object type.
Here's the draft. I've got the following classes:
-Country
-Image (Single Table Inheritance)
   -Map
   -Photo
Statements:
Map and Photo inherit from Image.
A Country can have as many Photos as possible.
A Country can have as many Maps as possible.
Situation:
The database is populated with plenty countries to test with, no maps,
no photos. I can add, remove, edit Photos and Maps as I please.
How to generate the Exception:
Upon adding a new Map object to the database everything works as
expected, the record is inserted, etc. When I try to load a Country
object that has a Map associated with it, it crashes because it's
trying to cast a Map record into the Photo collection (Upon examining
the SQL statement, it's not including the discriminator so it's
loading all records)
Here are the classes (at least the interesting part):
--- Country.cs
    [ActiveRecord]
    public class Country : ActiveRecordBase<Country>
    {
        // Omitted for clarity
        private int m_ID;
        private IList<Photo> m_photoList = new List<Photo>();
        private IList<Map> m_mapList = new List<Map>();
        [PrimaryKey(PrimaryKeyType.Native,
Access=PropertyAccess.NosetterPascalcaseMUndersc)]
        public int ID
        {
            get { return m_ID; }
        }
        [HasMany(typeof(Photo), Table="Image", ColumnKey="CountryId",
Inverse=true,
            Cascade=ManyRelationCascadeEnum.AllDeleteOrphan)]
        public IList<Photo> PhotoList
        {
            get { return m_photoList; }
            set { m_photoList = value; }
        }
        [HasMany(typeof(Map), Table="Image", ColumnKey="CountryId",
Inverse=true,
            Cascade=ManyRelationCascadeEnum.AllDeleteOrphan)]
        public IList<Map> MapList
        {
            get { return m_mapList; }
            set { m_mapList = value; }
        }
    }
--- Image.cs
    [ActiveRecord(DiscriminatorColumn="ImageType",
DiscriminatorType="String", DiscriminatorValue="Image")]
    public class Image : ActiveRecordBase<Image>
    {
        [BelongsTo("CountryId")]
        public Country Country
        {
            get { return m_country; }
            set { m_country = value; }
        }
     }
--- Photo.cs
[ActiveRecord(DiscriminatorValue="Photo")]
    public class Photo : Image
    {
        public Photo()  : base()
        {
            // Empty
        }
        public Photo(string imgName, string imgDescription, Country
imgCountry, string imgUrl)
            : base(imgName, imgDescription, imgCountry, imgUrl)
        {
            // Empty
        }
--- Map.cs
[ActiveRecord(DiscriminatorColumn="ImageType",
DiscriminatorType="String", DiscriminatorValue="Map")]
    public class Map : Image
    {
        // No custom variables yet
        public Map() : base()
        {
            // Empty
        }
        public Map(string imgName, string imgDescription, Country
imgCountry, string imgUrl) : base(imgName, imgDescription, imgCountry,
imgUrl)
        {
            // Empty
        }
    }
--- SQL Executed to get the Photo Collection
NHibernate: SELECT maplist0_.CountryId as CountryId__1_, maplist0_.ID
as ID1_, m
aplist0_.ID as ID3_0_, maplist0_.Name as Name3_0_,
maplist0_.Description as Desc
ript4_3_0_, maplist0_.URL as URL3_0_, maplist0_.CountryId as
CountryId3_0_ FROM
Image maplist0_ WHERE maplist0_.country...@p0; @p0 = '31'
--- SQL Executed to get the Map Collection
NHibernate: SELECT photolist0_.CountryId as CountryId__1_,
photolist0_.ID as ID1
_, photolist0_.ID as ID3_0_, photolist0_.Name as Name3_0_,
photolist0_.Descripti
on as Descript4_3_0_, photolist0_.URL as URL3_0_,
photolist0_.CountryId as Count
ryId3_0_ FROM Image photolist0_ WHERE photolist0_.country...@p0; @p0 =
'31'
As you can see it doesn't include the Discriminator in the query, no
idea why, otherwise it would work.
--- Exception
A first chance exception of type
'Castle.ActiveRecord.Framework.ActiveRecordException' occurred in
Castle.ActiveRecord.dll
System.Transactions Critical: 0 : <TraceRecord xmlns="http://
schemas.microsoft.com/2004/10/E2ETraceEvent/TraceRecord"
Severity="Critical"><TraceIdentifier>http://msdn.microsoft.com/
TraceCodes/System/ActivityTracing/2004/07/Reliability/Exception/
Unhandled</TraceIdentifier><Description>Unhandled exception</
Description><AppDomain>ConsoleApp.vshost.exe</
AppDomain><Exception><ExceptionType>Castle.ActiveRecord.Framework.ActiveRecordException,
Castle.ActiveRecord, Version=1.0.3.0, Culture=neutral,
PublicKeyToken=407dd0808d44fbdc</ExceptionType><Message>Could not
perform SlicedFindAll for Country</Message><StackTrace>   at
Castle.ActiveRecord.ActiveRecordBase.SlicedFindAll(Type targetType,
Int32 firstResult, Int32 maxResults, Order[] orders, ICriterion[]
criteria)
   at Castle.ActiveRecord.ActiveRecordBase.SlicedFindAll(Type
targetType, Int32 firstResult, Int32 maxResults, ICriterion[]
criteria)
   at Castle.ActiveRecord.ActiveRecordBase.FindOne(Type targetType,
ICriterion[] criteria)
   at DataAccessLayer.Country.FindCountryByName(String name) in C:
\Documents and Settings\ts36751\My Documents\Visual Studio
2008\Projects\HighlandAdventures\DataAccessLayer\Country.cs:line 108
   at ConsoleApp.Program.Main(String[] args) in C:\Documents and
Settings\ts36751\My Documents\Visual Studio 2008\Projects
\HighlandAdventures\ConsoleApp\Program.cs:line 20
   at System.AppDomain._nExecuteAssembly(Assembly assembly, String[]
args)
   at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence
assemblySecurity, String[] args)
   at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly
()
   at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
   at System.Threading.ExecutionContext.Run(ExecutionContext
executionContext, ContextCallback callback, Object state)
   at System.Threading.ThreadHelper.ThreadStart()</
StackTrace><ExceptionString>Castle.ActiveRecord.Framework.ActiveRecordException:
Could not perform SlicedFindAll for Country ---&amp;gt;
NHibernate.WrongClassException: Object with id: 1 was not of the
specified sublcass: DataAccessLayer.Photo (loading object was of wrong
class [DataAccessLayer.Map])
   at NHibernate.Loader.Loader.InstanceAlreadyLoaded(IDataReader rs,
Int32 i, ILoadable persister, EntityKey key, Object obj, LockMode
lockMode, ISessionImplementor session)
   at NHibernate.Loader.Loader.GetRow(IDataReader rs, ILoadable[]
persisters, EntityKey[] keys, Object optionalObject, EntityKey
optionalObjectKey, LockMode[] lockModes, IList hydratedObjects,
ISessionImplementor session)
   at NHibernate.Loader.Loader.GetRowFromResultSet(IDataReader
resultSet, ISessionImplementor session, QueryParameters
queryParameters, LockMode[] lockModeArray, EntityKey
optionalObjectKey, IList hydratedObjects, EntityKey[] keys, Boolean
returnProxies)
   at NHibernate.Loader.Loader.DoQuery(ISessionImplementor session,
QueryParameters queryParameters, Boolean returnProxies)
   at NHibernate.Loader.Loader.DoQueryAndInitializeNonLazyCollections
(ISessionImplementor session, QueryParameters queryParameters, Boolean
returnProxies)
   at NHibernate.Loader.Loader.LoadCollection(ISessionImplementor
session, Object id, IType type)
   at NHibernate.Loader.Collection.CollectionLoader.Initialize(Object
id, ISessionImplementor session)
   at
NHibernate.Persister.Collection.AbstractCollectionPersister.Initialize
(Object key, ISessionImplementor session)
   at NHibernate.Impl.SessionImpl.InitializeCollection
(IPersistentCollection collection, Boolean writing)
   at
NHibernate.Collection.AbstractPersistentCollection.ForceInitialization
()
   at NHibernate.Impl.SessionImpl.InitializeNonLazyCollections()
   at NHibernate.Loader.Loader.DoQueryAndInitializeNonLazyCollections
(ISessionImplementor session, QueryParameters queryParameters, Boolean
returnProxies)
   at NHibernate.Loader.Loader.DoList(ISessionImplementor session,
QueryParameters queryParameters)
   at NHibernate.Loader.Loader.ListIgnoreQueryCache
(ISessionImplementor session, QueryParameters queryParameters)
   at NHibernate.Loader.Loader.List(ISessionImplementor session,
QueryParameters queryParameters, ISet querySpaces, IType[]
resultTypes)
   at NHibernate.Loader.Criteria.CriteriaLoader.List
(ISessionImplementor session)
   at NHibernate.Impl.SessionImpl.Find(CriteriaImpl criteria, IList
results)
   at NHibernate.Impl.SessionImpl.Find(CriteriaImpl criteria)
   at NHibernate.Impl.CriteriaImpl.List()
   at Castle.ActiveRecord.ActiveRecordBase.SlicedFindAll(Type
targetType, Int32 firstResult, Int32 maxResults, Order[] orders,
ICriterion[] criteria)
   --- End of inner exception stack trace ---
   at Castle.ActiveRecord.ActiveRecordBase.SlicedFindAll(Type
targetType, Int32 firstResult, Int32 maxResults, Order[] orders,
ICriterion[] criteria)
   at Castle.ActiveRecord.ActiveRecordBase.SlicedFindAll(Type
targetType, Int32 firstResult, Int32 maxResults, ICriterion[]
criteria)
   at Castle.ActiveRecord.ActiveRecordBase.FindOne(Type targetType,
ICriterion[] criteria)
   at DataAccessLayer.Country.FindCountryByName(String name) in C:
\Documents and Settings\ts36751\My Documents\Visual Studio
2008\Projects\HighlandAdventures\DataAccessLayer\Country.cs:line 108
   at ConsoleApp.Program.Main(String[] args) in C:\Documents and
Settings\ts36751\My Documents\Visual Studio 2008\Projects
\HighlandAdventures\ConsoleApp\Program.cs:line 20
   at System.AppDomain._nExecuteAssembly(Assembly assembly, String[]
args)
   at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence
assemblySecurity, String[] args)
   at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly
()
   at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
   at System.Threading.ExecutionContext.Run(ExecutionContext
executionContext, ContextCallback callback, ...
        
For more, see 
http://support.castleproject.org/projects/AR/issues/view/AR-ISSUE-260
 
        
--
donjon
by Castle Stronghold
http://www.castle-donjon.com



--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Castle Project Development List" 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-devel?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to