-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Unabletocast 'NHibernate.Collection.PersistentBag' - Helpme
PostPosted: Thu Sep 27, 2007 9:46 am 
Newbie

Joined: Mon Jul 16, 2007 9:35 am
Posts: 17
Unable to cast object of type 'NHibernate.Collection.PersistentBag' to type 'ApplicationFramework.BE.Collections.CaseGroupCollection'.

When I use ILIST rather the way I have written above no issue for me. But whenever I use my own userCollection (CaseGroupCollection), I am facing this error.

This is very urgent and I refered in the forum it says to refer another link."http://sourceforge.net/mailarchive/".
I could not find specific help, as it is running through morethan 1000s mails. Kindly spare sometime to help me on this, as it very urgent to me for my application. Whoever came across and solved please pen down your valuable suggestions.

Hibernate version: 1.2

Source Code for my Entity:

Declaration:

protected int caseSetId = 0;
protected string caseSetName = null;
protected string setDescription = null;
protected CaseGroupCollection caseGroups = null;

Property:

public virtual CaseGroupCollection CaseGroups
{
get
{
return caseGroups;
}
set
{
string fullyQualifiedPropertyName = this.GetType().ToString() + "." + Property.CaseGroups.ToString();
caseGroups_IsChanged = caseGroups != value;

if (caseGroups != value)
{
caseGroups = value; if(caseGroups != caseGroups_InitialValue)
{
if (!dirtyProperties.Contains("CaseGroups"))
{
dirtyProperties.Add("CaseGroups");
}
}
else
{
if (dirtyProperties.Contains("CaseGroups"))
{
dirtyProperties.Remove("CaseGroups");
}
}
}
}
}


Mapping documents:
<?xml version="1.0" encoding="utf-8"?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
<class name="ApplicationFramework.BE.CaseSet, ApplicationFramework" table="CM_CASE_SET">
<id name="CaseSetId" type="Int32" unsaved-value="null">
<column name="CASE_SET_ID" length="4" sql-type="int" not-null="true" />
<generator class="assigned" />
</id>
<property name="CaseSetName" type="String">
<column name="CASE_SET_NAME" length="200" sql-type="varchar" not-null="true" />
</property>
<property name="SetDescription" type="String">
<column name="SET_DESCRIPTION" length="1500" sql-type="varchar" not-null="false" />
</property>
</property>
<bag name="CaseGroups" inverse="true" lazy="true" cascade="all-delete-orphan" generic="false">
<key column="CASE_SET_ID" />
<one-to-many class="ApplicationFramework.BE.CaseGroup, ApplicationFramework" />
</bag>
</class>
</hibernate-mapping>


Code between sessionFactory.openSession() and session.close():

public virtual Result Get(string query, RefParam< CaseSetCollection > collection)
{
collection.Value = new CaseSetCollection();

try
{
this.OpenSession();
IList list = _session.CreateQuery(query).List();

foreach (object o in list)
{
CaseSet m = (CaseSet)o;
collection.Value.Add(m);
}
return new Result(true);
}
catch (Exception ex)
{
return new Result(false, ApplicationManager.StackExceptionMessages(ex), ex);
}
}

Full stack trace of any exception that occurs:
at NHibernate.Persister.Entity.AbstractEntityPersister.SetPropertyValues(Object obj, Object[] values) in C:\NewWork\NHibernate Source\src\NHibernate\Persister\Entity\AbstractEntityPersister.cs:line 232
at NHibernate.Impl.SessionImpl.InitializeEntity(Object obj) in C:\NewWork\NHibernate Source\src\NHibernate\Impl\SessionImpl.cs:line 2959
at NHibernate.Loader.Loader.InitializeEntitiesAndCollections(IList hydratedObjects, Object resultSetId, ISessionImplementor session) in C:\NewWork\NHibernate Source\src\NHibernate\Loader\Loader.cs:line 615
at NHibernate.Loader.Loader.DoQuery(ISessionImplementor session, QueryParameters queryParameters, Boolean returnProxies) in C:\NewWork\NHibernate Source\src\NHibernate\Loader\Loader.cs:line 475
at NHibernate.Loader.Loader.DoQueryAndInitializeNonLazyCollections(ISessionImplementor session, QueryParameters queryParameters, Boolean returnProxies) in C:\NewWork\NHibernate Source\src\NHibernate\Loader\Loader.cs:line 181
at NHibernate.Loader.Loader.DoList(ISessionImplementor session, QueryParameters queryParameters) in C:\NewWork\NHibernate Source\src\NHibernate\Loader\Loader.cs:line 1798
at NHibernate.Loader.Loader.ListIgnoreQueryCache(ISessionImplementor session, QueryParameters queryParameters) in C:\NewWork\NHibernate Source\src\NHibernate\Loader\Loader.cs:line 1744
at NHibernate.Loader.Loader.List(ISessionImplementor session, QueryParameters queryParameters, ISet querySpaces, IType[] resultTypes) in C:\NewWork\NHibernate Source\src\NHibernate\Loader\Loader.cs:line 1738
at NHibernate.Hql.Classic.QueryTranslator.List(ISessionImplementor session, QueryParameters queryParameters) in C:\NewWork\NHibernate Source\src\NHibernate\Hql\Classic\QueryTranslator.cs:line 1124
at NHibernate.Impl.SessionImpl.Find(String query, QueryParameters parameters, IList results) in C:\NewWork\NHibernate Source\src\NHibernate\Impl\SessionImpl.cs:line 1770
at NHibernate.Impl.SessionImpl.Find(String query, QueryParameters parameters) in C:\NewWork\NHibernate Source\src\NHibernate\Impl\SessionImpl.cs:line 1728
at NHibernate.Impl.QueryImpl.List() in C:\NewWork\NHibernate Source\src\NHibernate\Impl\QueryImpl.cs:line 56
at ApplicationFramework.DAL.Bases.CaseSetDALBase.Get(String query, RefParam`1 collection) in C:\NewWork\ src\Components\ApplicationFramework\ApplicationFramework\DAL\Bases\CaseSetDALBase.cs:line 301


Name and version of the database you are using:
SQLServer 2005


Thank you very much for all your valuable time

Regards
Sudhagar.S


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.