-->
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: Hibernate Search with XML files mapping entities?
PostPosted: Mon Jun 14, 2010 10:28 am 
Beginner
Beginner

Joined: Mon Mar 01, 2010 12:24 pm
Posts: 22
Hi all,
I would like to know if I can use Hibernate Search programmatic API with an XML file mapping all my entities?

I tried to use a SearchMapping on MyCLassDefinition like this:
Here is the mapping:
Code:
<class name="MyClassDefinition" table="CLASS_DEF_">
    <id name="dbid" column="DBID_">
      <generator class="native" />
    </id>
    <property name="name" column="NAME_" />
    <property name="description" column="DESCRIPTION_" />
  ...
</class>

And the searchmapping code:
Code:
SearchMapping mapping = new SearchMapping();
mapping.entity(MyClassDefinition.class).indexed()
  .property("dbid", ElementType.FIELD).documentId().name("dbid")


But I got a SearchException : No document id in: MyClassDefinition

Regards,
Matti


Top
 Profile  
 
 Post subject: Re: Hibernate Search with XML files mapping entities?
PostPosted: Tue Jun 15, 2010 4:34 am 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
Hi,

I think it should work. Could you post the whole exception?


Top
 Profile  
 
 Post subject: Re: Hibernate Search with XML files mapping entities?
PostPosted: Tue Jun 15, 2010 5:19 am 
Beginner
Beginner

Joined: Mon Mar 01, 2010 12:24 pm
Posts: 22
Hi,
The main exception is: org.hibernate.HibernateException: could not init listeners (without any stacktrace)
I found the SearchException : No document id in: MyClassDefinition when I used the debugger.

I do not understand why I get the HibernateException becuase I had to my configuration the good listeners
Code:
  configuration.setListener("post-update", new FullTextIndexEventListener());
  configuration.setListener("post-insert", new FullTextIndexEventListener());
  configuration.setListener("post-delete", new FullTextIndexEventListener());
  configuration.setListener("post-collection-recreate", new FullTextIndexEventListener());
  configuration.setListener("post-collection-remove", new FullTextIndexEventListener());
  configuration.setListener("post-collection-update", new FullTextIndexEventListener());
  String[] listeners = new String[] {DefaultFlushEventListener.class.getName(), FullTextIndexEventListener.class.getName()};
  configuration.setListeners("flush", listeners);

And I set hibernate.search.autoregister_listeners to false.

Regards,
Matti


Top
 Profile  
 
 Post subject: Re: Hibernate Search with XML files mapping entities?
PostPosted: Tue Jun 15, 2010 7:05 am 
Beginner
Beginner

Joined: Mon Mar 01, 2010 12:24 pm
Posts: 22
I finally found the stack trace :)
Code:
org.hibernate.HibernateException: could not init listeners
   at org.hibernate.event.EventListeners.initializeListeners(EventListeners.java:205)
   at org.hibernate.cfg.Configuration.getInitializedEventListeners(Configuration.java:1396)
   at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1385)
   at ...
Caused by: org.hibernate.search.SearchException: No document id in: org.ow2.bonita.facade.def.InternalProcessDefinition
   at org.hibernate.search.engine.DocumentBuilderIndexedEntity.init(DocumentBuilderIndexedEntity.java:166)
   at org.hibernate.search.engine.DocumentBuilderContainedEntity.<init>(DocumentBuilderContainedEntity.java:117)
   at org.hibernate.search.engine.DocumentBuilderIndexedEntity.<init>(DocumentBuilderIndexedEntity.java:148)
   at org.hibernate.search.impl.SearchFactoryImpl.initDocumentBuilders(SearchFactoryImpl.java:519)
   at org.hibernate.search.impl.SearchFactoryImpl.<init>(SearchFactoryImpl.java:171)
   at org.hibernate.search.event.ContextHolder.getOrBuildSearchFactory(ContextHolder.java:60)
   at org.hibernate.search.event.FullTextIndexEventListener.initialize(FullTextIndexEventListener.java:122)
   at org.hibernate.event.EventListeners$1.processListener(EventListeners.java:198)
   at org.hibernate.event.EventListeners.processListeners(EventListeners.java:181)
   at org.hibernate.event.EventListeners.initializeListeners(EventListeners.java:194)

Hope it will help you
Regards,
Matti


Top
 Profile  
 
 Post subject: Re: Hibernate Search with XML files mapping entities?
PostPosted: Tue Jun 15, 2010 7:46 am 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
Hi,

could you please humor me and try this:

Code:
SearchMapping mapping = new SearchMapping();
mapping.entity(MyClassDefinition.class).indexed()
  .property("dbid", ElementType.FIELD).documentId().name("id")


Top
 Profile  
 
 Post subject: Re: Hibernate Search with XML files mapping entities?
PostPosted: Tue Jun 15, 2010 10:21 am 
Beginner
Beginner

Joined: Mon Mar 01, 2010 12:24 pm
Posts: 22
Hi,
I still get the same exception.

Regards,
Matthieu


Top
 Profile  
 
 Post subject: Re: Hibernate Search with XML files mapping entities?
PostPosted: Wed Jun 16, 2010 4:53 am 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
Might not be related, but you don't have to create a new listener for each event type. Just create one and use it for all events.


Top
 Profile  
 
 Post subject: Re: Hibernate Search with XML files mapping entities?
PostPosted: Wed Jun 16, 2010 9:54 am 
Beginner
Beginner

Joined: Mon Mar 01, 2010 12:24 pm
Posts: 22
Hi,
I found why Hibernate Search does not found the document id. The dbid field was not defined in MyClassDefinition but in its parent class. I put dbid field in myClassDefinition. And now the mapping works!

Thanks for your help


Top
 Profile  
 
 Post subject: Re: Hibernate Search with XML files mapping entities?
PostPosted: Fri Jun 18, 2010 3:15 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
We should raise a meaningful exception, it seems. Please open a JIRA issue.

_________________
Emmanuel


Top
 Profile  
 
 Post subject: Re: Hibernate Search with XML files mapping entities?
PostPosted: Mon Jun 28, 2010 10:02 am 
Beginner
Beginner

Joined: Mon Mar 01, 2010 12:24 pm
Posts: 22
Hi,

I open a new issue: http://opensource.atlassian.com/projects/hibernate/browse/HSEARCH-550

Regards,
Matti


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.