Dear All,
Please help me.
For my final project, I plan to implement hibernate search in an ejb module.
Since the call by a remote client to index my database, I have exeption below:
Code:
Caused by: org.hibernate.service.UnknownServiceException: Unknown service requested [org.hibernate.search.hcore.impl.SearchFactoryReference]
at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:184)
at org.hibernate.search.hcore.util.impl.ContextHelper.getSearchintegratorBySFI(ContextHelper.java:42)
at org.hibernate.search.hcore.util.impl.ContextHelper.getSearchintegratorBySessionImplementor(ContextHelper.java:37)
at org.hibernate.search.hcore.util.impl.ContextHelper.getSearchintegrator(ContextHelper.java:33)
at org.hibernate.search.impl.FullTextSessionImpl.getSearchIntegrator(FullTextSessionImpl.java:179)
at org.hibernate.search.impl.FullTextSessionImpl.createMassIndexerFactory(FullTextSessionImpl.java:191)
at org.hibernate.search.impl.FullTextSessionImpl.createIndexer(FullTextSessionImpl.java:161)
at org.idalfinancial.fxproject.ejb3.beans.session.module.core.indexation.HibernateIndexer.indexer(HibernateIndexer.java:77)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.jboss.as.ee.component.ManagedReferenceMethodInterceptor.processInvocation(ManagedReferenceMethodInterceptor.java:52)
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)
at org.jboss.invocation.InterceptorContext$Invocation.proceed(InterceptorContext.java:437)
at org.jboss.as.weld.ejb.Jsr299BindingsInterceptor.doMethodInterception(Jsr299BindingsInterceptor.java:82)
at org.jboss.as.weld.ejb.Jsr299BindingsInterceptor.processInvocation(Jsr299BindingsInterceptor.java:93)
at org.jboss.as.ee.component.interceptors.UserInterceptorFactory$1.processInvocation(UserInterceptorFactory.java:63)
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)
at org.jboss.as.ejb3.component.invocationmetrics.ExecutionTimeInterceptor.processInvocation(ExecutionTimeInterceptor.java:43)
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)
at org.jboss.as.jpa.interceptor.SBInvocationInterceptor.processInvocation(SBInvocationInterceptor.java:47)
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)
at org.jboss.invocation.InterceptorContext$Invocation.proceed(InterceptorContext.java:437)
at org.jboss.weld.ejb.AbstractEJBRequestScopeActivationInterceptor.aroundInvoke(AbstractEJBRequestScopeActivationInterceptor.java:73)
at org.jboss.as.weld.ejb.EjbRequestScopeActivationInterceptor.processInvocation(EjbRequestScopeActivationInterceptor.java:83)
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)
at org.jboss.as.ee.concurrent.ConcurrentContextInterceptor.processInvocation(ConcurrentContextInterceptor.java:45)
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)
at org.jboss.invocation.InitialInterceptor.processInvocation(InitialInterceptor.java:21)
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)
at org.jboss.invocation.ChainedInterceptor.processInvocation(ChainedInterceptor.java:61)
at org.jboss.as.ee.component.interceptors.ComponentDispatcherInterceptor.processInvocation(ComponentDispatcherInterceptor.java:52)
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)
at org.jboss.as.ejb3.component.pool.PooledInstanceInterceptor.processInvocation(PooledInstanceInterceptor.java:51)
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)
at org.jboss.as.ejb3.tx.CMTTxInterceptor.invokeInOurTx(CMTTxInterceptor.java:275)
... 44 more
Please find below my codes :
1. my ejb session :
HibernateIndexer.javaCode:
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. My ejb enties :
TgPersonnePer.javaCode:
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 and getter
...................
}
TgPersonneMoralePer.javaCode:
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 and getter
.................
}
3. my jboss structure file :
boss-deployment-structure.xmlCode:
<?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>
4. my hibernate config file :
hibernate.cfg.xmlCode:
<?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 all executed SQL to 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>