ejb 3.1 - Error with hibernate search in ejbModule -
for final project, plan implement hibernate search in ejb module. since call remote client index database, have exeption below:
caused by: org.hibernate.service.unknownserviceexception: unknown service requested [org.hibernate.search.hcore.impl.searchfactoryreference]
please find below codes :
1. ejb session:
import javax.annotation.postconstruct; import javax.ejb.localbean; import javax.ejb.stateless; import org.apache.lucene.search.query; import org.hibernate.session; import org.hibernate.sessionfactory; import org.hibernate.transaction; import org.hibernate.cfg.configuration; import org.hibernate.search.fulltextsession; import org.hibernate.search.search; import org.hibernate.search.query.dsl.querybuilder; /** * session bean implementation class hibernateindexer */ @stateless(name="hind") @localbean public class hibernateindexer implements hibernateindexerremote, hibernateindexerlocal { protected configuration config; protected sessionfactory sessionfactory; protected session session; protected fulltextsession ftx; /** * default constructor. */ public hibernateindexer() { // todo auto-generated constructor stub } @postconstruct private void init(){ config=new configuration(); sessionfactory= config.configure().buildsessionfactory(); session=sessionfactory.opensession(); ftx=search.getfulltextsession(session); } public void indexer(){ try { ftx.createindexer().startandwait(); } catch (interruptedexception e) { // todo auto-generated catch block e.printstacktrace(); } session.close(); } }
2. ejb entities
2.1 tgpersonneper.java
import org.hibernate.search.annotations.analyze; import org.hibernate.search.annotations.documentid; import org.hibernate.search.annotations.field; import org.hibernate.search.annotations.index; import org.hibernate.search.annotations.indexed; import org.hibernate.search.annotations.indexedembedded; import org.hibernate.search.annotations.store; @indexed public class tgpersonneper implements java.io.serializable { @documentid private string perid; @indexedembedded private tgpersonnemoraleper tgpersonnemoraleper; public tgpersonneper() { } public tgpersonneper(string perid) { this.perid = perid; } // setter , getter ................... }
2.2 tgpersonnemoraleper.java
import org.hibernate.search.annotations.field; public class tgpersonnemoraleper implements java.io.serializable { private string perid; private tgpersonneper tgpersonneper; @field private string perdenosociale; @field private string persigle; public tgpersonnemoraleper() { } public tgpersonnemoraleper(tgpersonneper tgpersonneper) { this.tgpersonneper = tgpersonneper; } // setter , getter ................. }
3. hibernate config file : hibernate.cfg.xml
<?xml version="1.0" encoding="utf-8"?> <!doctype hibernate-configuration public "-//hibernate/hibernate configuration dtd 3.0//en" "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd"> <hibernate-configuration> <session-factory> <property name="hibernate.bytecode.use_reflection_optimizer">false</property> <property name="hibernate.connection.driver_class">oracle.jdbc.oracledriver</property> <property name="hibernate.connection.url">jdbc:oracle:thin:@localhost:1521:xe</property> <property name="hibernate.connection.username">exam</property> <property name="hibernate.connection.password">azerty</property> <property name="hibernate.dialect">org.hibernate.dialect.oracle10gdialect</property> <property name="hibernate.search.autoregister_listeners">true</property> <property name="hibernate.validator.apply_to_ddl">false</property> <!-- echo executed sql stdout --> <property name="hibernate.hbm2ddl.auto">update</property> <property name="hibernate.show_sql">true</property> <!-- hibernate research configuration--> <property name="hibernate.search.default.directory_provider">filesystem</property> <property name="hibernate.search.default.indexbase">d:\lucene\indexes</property> <property name="hibernate.ejb.event.post-insert">org.hibernate.search.event.fulltextindexeventlistener</property> <property name="hibernate.ejb.event.post-update">org.hibernate.search.event.fulltextindexeventlistener</property> <property name="hibernate.ejb.event.post-delete">org.hibernate.search.event.fulltextindexeventlistener</property> <mapping resource="org/module/entities/tgpersonnemoraleper.hbm.xml" /> <mapping resource="org/module/entities/tgpersonneper.hbm.xml" /> </session-factory> </hibernate-configuration>
4. jboss deployment structure : jboss-deployment-structure.xml
<?xml version="1.0" encoding="utf-8"?> <jboss-deployment-structure> <deployment> <dependencies> <module name="org.hibernate" slot="main"/> <module name="org.jboss.logging" slot="main"/> <module name="javax.transaction.api" slot="main"/> <module name="org.javassist"/> <!-- module de hibernate search --> <module name="org.hibernate.search.orm" slot="main"/> <module name="org.hibernate.search.engine" slot="main"/> <module name="org.apache.lucene" slot="main"/> <module name="org.apache.lucene.internal" slot="main"/> </dependencies> <exclusions> <module name="org.javassist" slot="main"/> </exclusions> </deployment> </jboss-deployment-structure>
you need expose services hibernate search orm module.
so following in order:
<module name="org.hibernate.search.orm" services="export" slot="main"/>
adding module should enough hibernate search running, shouldn't need add other modules (engine , lucene).
Comments
Post a Comment