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.  [ 7 posts ] 
Author Message
 Post subject: switching from bag to set "No implementation of generic
PostPosted: Mon Jun 23, 2008 8:43 pm 
Newbie

Joined: Mon Jun 23, 2008 6:38 pm
Posts: 13
Hi,

I have a problem when I changed the collection from <bag> to <set>. I have 3 tables, Jobseeker, Application and Job respectively.

Jobseeker table
JobseekerID
Name.............


Application table
ID
JobseekerId
JobID
When

Job
JobID
JobTitle.............

the mapping look like the followings:


<class name="Entity.Jobseeker, Entity" table="Jobseeker ">
<id name="Id" column="JobseekerID" type="int">
<generator class="native" />
</id>
<bag name="AppliedJobs" order-by="`When` Desc" >
<key column="JobseekerId" />
<one-to-many class="Entity.Application, Entity" />
</bag>
</class>

<class name="Entity.Application, Entity" table="Application" lazy="true">
<id name="Id" column="ID" type="int">
<generator class="native" />
</id>
<property name="JobID" column="JobID" type="int" insert="false" />
<property name="JobseekerId" column="JobseekerId" type="int" />
<property name="When" column="`when`" type="DateTime" />

<many-to-one name="AppliedJob" class="Entity.Job, Entity" fetch="join" column="JobID" not-found="ignore" not-null="true" />
</class>

Initially, I used <bag>. It worked just find. The only thing was that my old application created lots of dups. Also, the row remains there in the application table after a job is deleted. Therefore, I switched it to use <set> that helps me dedup all those dups created by my old app. However, nhibernate complains when I try to sort the collection like I did for <map>:

<set name="AppliedJobs" order-by="`When` Desc" >
<key column="JobseekerId" />
<one-to-many class="Entity.Application, Entity" />
</set>


The exception message was "No implementation of generic set". Did I miss something? Can anyone help me with this? Thanks a lot.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 24, 2008 2:06 am 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
Can you post your code ? Sounds like a problem with the type. You have to change the property from IList to ISet, when you switch to set. The ISet stuff comes with Iesi.Collections.

_________________
--Wolfgang


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 24, 2008 12:14 pm 
Newbie

Joined: Mon Jun 23, 2008 6:38 pm
Posts: 13
Thank you for your response. I did use ISet for the type.

namespace AfterCollege.Wrapper
{
[Serializable]
public class Jobseeker
{
#region Member Variables

protected int _jobseekerId;
[NonSerialized]
protected ISet<Application> _appliedJobs;

public virtual int JobseekerId
{
get { return this.JobseekerId; }
set { this.JobseekerId= value; }
}

#endregion

[System.Xml.Serialization.XmlIgnore]
public virtual ISet<Application> AppliedJobs
{
get { return _appliedJobs; }
set { _appliedJobs = value; }
}


}


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 24, 2008 12:22 pm 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
Can you post the stacktrace and the code where you try to retrieve the objects ?

And try generic="true" on the set mapping.

_________________
--Wolfgang


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 24, 2008 2:03 pm 
Newbie

Joined: Mon Jun 23, 2008 6:38 pm
Posts: 13
I added generic="true" and I still get the same message. The stacktrace looks like this. I tried to execute the query in my sql console. It seems fine.


- InnerException {"could not initialize a collection: [Entity.Jobseeker.AppliedJobs#268170][SQL: SELECT appliedjob0_.jobseekerid as jobseekerid__2_, appliedjob0_.ID as ID2_, appliedjob0_.ID as ID27_1_, appliedjob0_.jobid as jobid27_1_, appliedjob0_.jobseekerid as jobseekerid27_1_, job1_.jobid as jobid5_0_, job1_.jobtitle as jobtitle5_0_ FROM application appliedjob0_ inner join job job1_ on appliedjob0_.jobid=job1_.recid WHERE appliedjob0_.jobseekerid=? ORDER BY appliedjob0_.`When` Desc]"} NHibernate.ADOException
+ Data {System.Collections.ListDictionaryInternal} System.Collections.IDictionary {System.Collections.ListDictionaryInternal}
HelpLink null string
+ InnerException {"No implementation of generic set with ordering"} System.Exception {System.NotImplementedException}
Message "could not initialize a collection: [Entity.Jobseeker.AppliedJobs#268170][SQL: SELECT appliedjob0_.jobseekerid as jobseekerid__2_, appliedjob0_.ID as ID2_, appliedjob0_.ID as ID27_1_, appliedjob0_.jobid as jobid27_1_, appliedjob0_.jobseekerid as jobseekerid27_1_, job1_.jobid as jobid5_0_, job1_.jobtitle as jobtitle5_0_ FROM application appliedjob0_ inner join job job1_ on appliedjob0_.jobid=job1_.recid WHERE appliedjob0_.jobseekerid=? ORDER BY appliedjob0_.`When` Desc]" string
Source "NHibernate" string
StackTrace " at NHibernate.Loader.Loader.LoadCollection(ISessionImplementor session, Object id, IType type)\r\n at NHibernate.Loader.Collection.CollectionLoader.Initialize(Object id, ISessionImplementor session)\r\n at NHibernate.Persister.Collection.AbstractCollectionPersister.Initialize(Object key, ISessionImplementor session)\r\n at NHibernate.Impl.SessionImpl.InitializeCollection(IPersistentCollection collection, Boolean writing)\r\n at NHibernate.Collection.AbstractPersistentCollection.Initialize(Boolean writing)" string
+ TargetSite {Void LoadCollection(NHibernate.Engine.ISessionImplementor, System.Object, NHibernate.Type.IType)} System.Reflection.MethodBase {System.Reflection.RuntimeMethodInfo}
+ Static members


Stacktrace in InnerException:

+ [System.NotImplementedException] {"No implementation of generic set with ordering"} System.NotImplementedException
+ Data {System.Collections.ListDictionaryInternal} System.Collections.IDictionary {System.Collections.ListDictionaryInternal}
HelpLink null string
+ InnerException null System.Exception
Message "No implementation of generic set with ordering" string
Source "NHibernate" string
StackTrace " at NHibernate.Collection.Generic.PersistentGenericSet`1.BeforeInitialize(ICollectionPersister persister)\r\n at NHibernate.Impl.SessionImpl.GetLoadingCollection(ICollectionPersister persister, Object id, Object resultSetId)\r\n at NHibernate.Loader.Loader.HandleEmptyCollections(Object[] keys, Object resultSetId, ISessionImplementor session)\r\n at NHibernate.Loader.Loader.DoQuery(ISessionImplementor session, QueryParameters queryParameters, Boolean returnProxies)\r\n at NHibernate.Loader.Loader.DoQueryAndInitializeNonLazyCollections(ISessionImplementor session, QueryParameters queryParameters, Boolean returnProxies)\r\n at NHibernate.Loader.Loader.LoadCollection(ISessionImplementor session, Object id, IType type)" string
+ TargetSite {Void BeforeInitialize(NHibernate.Persister.Collection.ICollectionPersister)} System.Reflection.MethodBase {System.Reflection.RuntimeMethodInfo}


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 24, 2008 3:41 pm 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
hmmm ....

Quote:
at NHibernate.Collection.Generic.PersistentGenericSet`1.BeforeInitialize(ICollectionPersister persister)


Code:
public override void BeforeInitialize(ICollectionPersister persister)
{
   if (persister.HasOrdering)
   {
      throw new NotImplementedException("No implementation of generic set with ordering");
   }
   else
   {
      internalSet = (ISet<T>) persister.CollectionType.Instantiate();
   }
}


looks like "order-by" is not supported with a set ... :-( ... I always thought, that order-by is appied to the sql and nothing more ... according to chapter 6.6 of the reference documentation this should work as you implemented it ...

... howeverm I found this http://jira.nhibernate.org/browse/NH-939

_________________
--Wolfgang


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 24, 2008 4:11 pm 
Newbie

Joined: Mon Jun 23, 2008 6:38 pm
Posts: 13
wolli wrote:

Code:
public override void BeforeInitialize(ICollectionPersister persister)
{
   if (persister.HasOrdering)
   {
      throw new NotImplementedException("No implementation of generic set with ordering");
   }
   else
   {
      internalSet = (ISet<T>) persister.CollectionType.Instantiate();
   }
}



I see now. I was wondering why it's not implemented. Anyways, wolli, thank you very much.


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

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.