-->
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.  [ 10 posts ] 
Author Message
 Post subject: Not a mapped entity
PostPosted: Mon Jul 28, 2008 11:46 am 
Newbie

Joined: Mon Jul 28, 2008 11:04 am
Posts: 5
NHibernate version:

NHibernate-1.2.1.GA-debug

Mapping documents:

Many to many relationship. I proved it works with HQL and a IQuery.

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

String text = "test";

Lucene.Net.Analysis.Analyzer analyzer = new Lucene.Net.Analysis.SimpleAnalyzer();

MultiFieldQueryParser parser = new MultiFieldQueryParser(new String[] { "Name" }, analyzer);
Query queryObj = parser.Parse(text);

ISessionFactory sessionFactory = NHibernateHelper.GetSessionFactory();
Configuration config = new Configuration();
SearchFactory.Initialize(config,sessionFactory);

ISession session = sessionFactory.OpenSession(new SearchInterceptor());

IFullTextSession textSession = NHibernate.Search.Search.CreateFullTextSession(session);

IQuery nhQuery = textSession.CreateFullTextQuery(queryObj, new Type[] { typeof(Keyword) });

IList<Keyword> keywords = nhQuery.List<Keyword>();

Error message:

[HibernateException: Not a mapped entity: Stuff.Other.Keyword]

Question:

Trying to use NHibernate.Search and Lucene.Net together. Has anyone come across this error? I can't find any documentation on the error message and can't seem to find a solution. If you want more information i am happy to provide it.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 28, 2008 12:40 pm 
Expert
Expert

Joined: Thu Jul 05, 2007 9:38 am
Posts: 287
I don't know about the N Version of Hibernate and Lucene, but it sounds like the Class wasn't mapped properly. Maybe the entry in hibernate.cfg.xml is missing?

Jens

_________________
Please rate useful posts.


Schauderhaft: Softwaredevelopment, Projectmanagement, Qualitymanagement and all things "schauderhaft"


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 29, 2008 6:04 am 
Newbie

Joined: Mon Jul 28, 2008 11:04 am
Posts: 5
Thanks for the reply, I can't see a mistake in my mapping file though, maybe you can see it?

Mapping File

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" default-lazy="true" namespace="Stuff.Other" assembly="Stuff">
<class name="Keyword,Stuff" table="Keyword" lazy="true">

<!-- Primary Key(s) -->
<id name="Id" unsaved-value="0">
<generator class="native"/>
</id>

<!-- Properties -->
<property name="Name" not-null="true" length="50" />
<property name="Modified" not-null="true" />

<!-- One-To-Many relations -->
<bag name="Categories" lazy="false" table="CategoryKey" cascade="all" inverse="true">
<key column="Id"/>
<many-to-many class="Category" column="categoryId"/>
</bag>

</class>
</hibernate-mapping>

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" default-lazy="true" namespace="Stuff.Other" assembly="Stuff">
<class name="Category,Stuff" table="Category" lazy="true">

<!-- Primary Key(s) -->
<id name="Id" unsaved-value="0">
<generator class="native"/>
</id>

<!-- Properties -->
<property name="ParentId" />
<property name="Modified" not-null="true" />
<property name="Name" not-null="true" length="80" />

<!-- One-To-Many relations -->
<bag name="Keywords" lazy="false" cascade="none" table="CategoryKey" inverse="true" >
<key column="Id"/>
<many-to-many class="Keyword" column="keywordId"/>
</bag>

</class>
</hibernate-mapping>


Classes

[Indexed]
public class Keyword {
public Keyword() { }

[DocumentId]
protected int mId;
public virtual int Id {
get { return mId; }
set { mId = value; }
}

protected DateTime mModified;
public virtual DateTime Modified {
get { return mModified; }
set { mModified = value; }
}

[Field(Index.Tokenized, Store = Store.Yes)]
protected String mName;
public virtual String Name {
get { return mName; }
set { mName = value; }
}

[Field(Index.Tokenized, Store = Store.Yes)]
protected IList<Category> mCategories;
public virtual IList<Category> Categories {
get { return mCategories; }
set { mCategories = value; }
}
}

[Indexed]
public class Category {
public Category() { }

[DocumentId]
protected int mId;
public virtual int Id {
get { return mId; }
set { mId = value; }
}

protected DateTime mModified;
public virtual DateTime Modified {
get { return mModified; }
set { mModified = value; }
}


protected int mParentId;
public virtual int ParentId {
get { return mParentId; }
set { mParentId = value; }
}

[Field(Index.Tokenized, Store = Store.Yes)]
protected String mName;
public virtual String Name {
get { return mName; }
set { mName = value; }
}

[Field(Index.Tokenized, Store = Store.Yes)]
protected IList<Keyword> mKeywords;
public virtual IList<Keyword> Keywords{
get { return mKeywords; }
set { mKeywords = value; }
}
protected int mSiteId;
public virtual int SiteId {
get { return mSiteId; }
set { mSiteId = value; }
}
}


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 29, 2008 11:46 am 
Expert
Expert

Joined: Thu Jul 05, 2007 9:38 am
Posts: 287
If I get it right you are showing the


shouldn't that
<class name="Keyword,Stuff" table="Keyword" lazy="true">
be
<class name="Keyword.Stuff" table="Keyword" lazy="true">

? (dot instead of colon)

You are showing the Keyword.stuff.xml (or similiar I think)

There also should be a hibernate.config.xml referencing the document/class above.

_________________
Please rate useful posts.


Schauderhaft: Softwaredevelopment, Projectmanagement, Qualitymanagement and all things "schauderhaft"


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 29, 2008 12:06 pm 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
Quote:
ISessionFactory sessionFactory = NHibernateHelper.GetSessionFactory();
Configuration config = new Configuration();
SearchFactory.Initialize(config,sessionFactory);


What are you doing in "NHibernateHelper.GetSessionFactory()" ? You're using two different configuration objects for the session and the search factory. Is that intended ?

_________________
--Wolfgang


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 29, 2008 12:28 pm 
Newbie

Joined: Mon Jul 28, 2008 11:04 am
Posts: 5
Here is the nhibernatehelper code although its pretty standard I believe.

public class NHibernateHelper {

private const string CurrentSessionKey = "nhibernate.current_session";
private static readonly ISessionFactory sessionFactory;

static NHibernateHelper() {
sessionFactory = new Configuration().Configure().BuildSessionFactory();
}

public static ISession GetCurrentSession() {
HttpContext context = HttpContext.Current;
ISession currentSession = context.Items[CurrentSessionKey] as ISession;

if (currentSession == null) {
currentSession = sessionFactory.OpenSession();
context.Items[CurrentSessionKey] = currentSession;
}

return currentSession;
}

public static ISessionFactory GetSessionFactory() {
return sessionFactory;
}

Well i am using a web.config so there is no hibernate.cfg.xml. Changing the mapping file like you suggested doesn't work at all. The examples I have been reading all use the SearchFactory.Initialize(config,sessionFactory); line, could this be incorrect? I really appreciate the suggestions as I am struggling to find a solution.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 30, 2008 5:56 am 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
hmmmm ... you add the assemblies/resource files in the config ? Pls post you web.config, too.

_________________
--Wolfgang


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 30, 2008 9:21 am 
Newbie

Joined: Mon Jul 28, 2008 11:04 am
Posts: 5
Web.config looks like this:

<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
<session-factory>
<property name="dialect">NHibernate.Dialect.MsSql7Dialect</property>
<property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
<property name="connection.driver_class">NHibernate.Driver.SqlClientDriver</property>
<property name="connection.connection_string">Server=randomserver;initial catalog=suppliers;User id=stuff;Password=stuff;</property>
<property name="show_sql">true</property>
<property name="hibernate.search.default.directory_provider">NHibernate.Search.Storage.FSDirectoryProvider, NHibernate.Search</property>
<property name="hibernate.search.default.indexBase">~/Index</property>
<mapping assembly="ConfettiCore"/>
</session-factory>

I removed the hibernate.search.default.directory_provider and hibernate.search.default.indexbase. Replacing it with:

config.SetProperty("hibernate.search.default.directory_provider", typeof(RAMDirectoryProvider).AssemblyQualifiedName);
config.SetProperty(NHibernate.Search.Environment.AnalyzerClass, typeof(StopAnalyzer).AssemblyQualifiedName);
config.Configure();

I now get a different error message: Unable to guess IFieldBridge for mKeywords. So I am not sure which approach is correct, although both should have similar effect? Can't find any information on this new error message either.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 30, 2008 9:41 am 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
hmm, I wonder if the problem is this:


Code:
[Field(Index.Tokenized, Store = Store.Yes)]
protected IList<Keyword> mKeywords;
public virtual IList<Keyword> Keywords{


You've mapped the property, but assigned the attribute to the field. But I'm not familar with either NHibernate.Search nor Lucene. You can try the user group on google, maybe you find more help there for this specific problem: http://groups.google.com/group/nhusers?hl=en

_________________
--Wolfgang


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 31, 2008 4:44 am 
Newbie

Joined: Mon Jul 28, 2008 11:04 am
Posts: 5
I changed it to the methods instead of the attributes and i still receive the same error message. I will check out the Google group, thanks.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 10 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.