-->
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.  [ 2 posts ] 
Author Message
 Post subject: Problem integrating Hibsearch in a Spring & hibernat/JPA App
PostPosted: Sun May 08, 2011 1:13 pm 
Newbie

Joined: Sun May 08, 2011 12:06 pm
Posts: 1
Hello everybody!
I have a Spring and hibernate/JPA Application which works well.
I started to integrate Hibernate search a few days ago, but I'm a beginner so it's hard.
Here are some .jar I use for this app:
hibernate3.jar
hibernate-annotations.jar
hibernate-entitymanager-3.2.1.ga.jar
hibernate-entitymanager.jar
spring-2.5.6.jar
lucene-core-3.1.0.jar
hibernate-core-3.6.4.Final.jar
hibernate-search-3.4.0.Final.jar
hibernate-search-infinispan-3.4.0.Final.jar

I checked the directory I indicated for HibSearch indexes but there is nothing, and I get these errors:

[color=#0000FF]java.lang.NoClassDefFoundError: javax/persistence/LockTimeoutException
at org.hibernate.search.jpa.impl.FullTextEntityManagerImpl.createFullTextQuery(FullTextEntityManagerImpl.java:101)
at dao.Dao.filterPhotoWithArticle(Dao.java:279)
at service.Service.filterPhotoWithArticle(Service.java:320)
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.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:307)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:182)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:149)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:106)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
[/color]

Here are my spring.xml, persistence.xml, my class (in which I want to use HibSearch) and my function using HibSearch:

Spring.xml:

Code:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xmlns:tx="http://www.springframework.org/schema/tx"
   xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd">

   <!-- couches applicatives -->
   <bean id="dao" class="dao.Dao" />
   <bean id="service" class="service.Service">
      <property name="dao" ref="dao" />
   </bean>

   <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
      <property name="dataSource" ref="dataSource" />
      <property name="jpaVendorAdapter">
         <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
            <!--
               <property name="showSql" value="true" />
            -->
            <property name="databasePlatform" value="org.hibernate.dialect.MySQL5InnoDBDialect" />
            <property name="generateDdl" value="true" />
         </bean>
      </property>
      <property name="loadTimeWeaver">
         <bean class="org.springframework.instrument.classloading.InstrumentationLoadTimeWeaver" />
      </property>
   </bean>

   <!-- la source de donnéees DBCP -->
   <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
      <property name="driverClassName" value="com.mysql.jdbc.Driver" />
      <property name="url" value="jdbc:mysql://localhost:3306/test" />
      <property name="username" value="jpa" />
      <property name="password" value="" />
   </bean>

   <!-- le gestionnaire de transactions -->
   <tx:annotation-driven transaction-manager="txManager" />
   <bean id="txManager" class="org.springframework.orm.jpa.JpaTransactionManager">
      <property name="entityManagerFactory" ref="entityManagerFactory" />
   </bean>

   <!-- traduction des exceptions -->
   <bean class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor" />

   <!-- persistence -->
   <bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" />

</beans>



persistence.xml:

Code:
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="1.0"
   xmlns="http://java.sun.com/xml/ns/persistence"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">
   
   <persistence-unit name="jpa" transaction-type="RESOURCE_LOCAL">
      <properties>
            <!--  HSearch settings -->
            <property name="hibernate.search.default.indexBase" value="/Users/Amine%20NABIL/workspace/article" />
            <property name="hibernate.search.default.directory_provider" value="org.hibernate.search.store.FSDirectoryProvider" />
   <!--<property name="post-update" value="org.hibernate.search.event.FullTextIndexEventListener"/>
              <property name="post-insert" value="org.hibernate.search.event.FullTextIndexEventListener"/>
         <property name="post-delete" value="org.hibernate.search.event.FullTextIndexEventListener"/>
      </properties>-->
   </persistence-unit>
   
   <!--<persistence-unit name="jpa" transaction-type="RESOURCE_LOCAL"/>-->
</persistence>


Classe:

Code:
package entites;

import java.io.Serializable;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Version;


import org.apache.lucene.analysis.standard.StandardAnalyzer;
import org.apache.solr.analysis.PhoneticFilterFactory;
import org.apache.solr.analysis.StandardTokenizerFactory;
import org.apache.solr.analysis.StopFilterFactory;
import org.apache.solr.analysis.SynonymFilterFactory;
import org.hibernate.search.annotations.Analyzer;
import org.hibernate.search.annotations.AnalyzerDef;
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.Parameter;
import org.hibernate.search.annotations.Store;
import org.hibernate.search.annotations.TokenFilterDef;
import org.hibernate.search.annotations.TokenizerDef;
import org.hibernate.search.annotations.Boost;

@SuppressWarnings( { "unused", "serial" })
@Entity
@Indexed
@Table(name="article")
@Analyzer(impl=StandardAnalyzer.class)

public class Article implements Serializable {
   
   @Id
   @DocumentId
   @Column(name = "ID", nullable = false)
   @GeneratedValue(strategy = GenerationType.AUTO)
   private int id;
   
   
   @Column(name = "DATE_MODIF", nullable = true)
   @Temporal(TemporalType.TIMESTAMP)// TIMESTAMP pour coder une date avec heure
   private Date dateModif;
   
   @Column(name = "COMMENTAIRE", length = 1000, nullable = false)
   //@org.hibernate.annotations.Index(name = "commentaireIndex")
   @Field(index=Index.TOKENIZED, store=Store.YES)
   private String commentaire;
   
   @Column(nullable = true)
   @Version
   private int version;

   //@OneToOne(mappedBy = "article")
   //private Photo photo;

   // relation inverse Article -> Photo
   //@ManyToMany(mappedBy = "articles")
   //private Set<Photo> photos = new HashSet<Photo>();
   
   // relation principale Article (many) -> Category (one)
   // implémentée par une clé étrangère (categorie_id) dans Article
   // 1 Article a nécessairement 1 Categorie (nullable=false)
   @ManyToOne(fetch=FetchType.LAZY)
   @JoinColumn(name = "ID_PHOTO", nullable = false)
   @IndexedEmbedded
   private Photo photo;
   
   //Constructors
   public Article() {
      
   }

   public Article(int id, String commentaire, int version, Date dateModif) {
      this.id = id;
      this.dateModif = dateModif;
      this.commentaire = commentaire;
      this.version = version;
   }
   
   public Article(String commentaire, int version, Date dateModif) {
      this.dateModif = dateModif;
      this.commentaire = commentaire;
      this.version = version;
   }
   
   public Article(String commentaire, Date dateModif) {
      this.dateModif = dateModif;
      this.commentaire = commentaire;
   }
   
   public Article(String commentaire) {
      this.commentaire = commentaire;
   }
   
   //getters and setters
   
   public int getId() {
      return id;
   }

   /**
    * @param id the id to set
    */
   public void setId(int id) {
      this.id = id;
   }
   
   /**
    * @return the dateModif
    */
   public Date getDateModif() {
      return dateModif;
   }

   /**
    * @return the commentaire
    */
   public String getCommentaire() {
      return commentaire;
   }

   /**
    * @param dateModif the dateModif to set
    */
   public void setDate_modif(Date dateModif) {
      this.dateModif = dateModif;
   }

   /**
    * @param commentaire the commentaire to set
    */
   public void setCommentaire(String commentaire) {
      this.commentaire = commentaire;
   }

   public Photo getPhoto() {
      return photo;
   }

   public void setPhoto(Photo photo) {
      this.photo = photo;
   }
   
}
   


and finally the code to release a search:

Code:
package dao;

import java.util.HashMap;
import java.util.List;
import java.util.Date;
import java.util.Map;
import java.util.logging.Logger;
import java.util.logging.Level;

import javax.annotation.PostConstruct;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.EntityTransaction;
import javax.persistence.Persistence;
import javax.persistence.PersistenceContext;
import javax.persistence.PersistenceContextType;

import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.analysis.TokenStream;

import org.apache.lucene.analysis.standard.StandardAnalyzer;
import org.apache.lucene.index.Term;

import org.apache.lucene.queryParser.MultiFieldQueryParser;
import org.apache.lucene.queryParser.ParseException;
import org.apache.lucene.queryParser.QueryParser;
import org.apache.lucene.search.BooleanClause;
import org.apache.lucene.search.BooleanQuery;
import org.apache.lucene.search.FuzzyQuery;
import org.apache.lucene.util.Version;
import org.hibernate.search.jpa.FullTextEntityManager;
import org.hibernate.search.jpa.Search;
import org.hibernate.search.jpa.FullTextQuery;
import org.hibernate.search.jpa.impl.FullTextEntityManagerImpl;
import org.slf4j.impl.StaticLoggerBinder;

import entites.Photo;
import entites.Tag;
import entites.Article;
import entites.PhotoTag;

//@SuppressWarnings("unused")
public class Dao implements IDao {

   @PersistenceContext
   private EntityManager em;
   FullTextEntityManager fullTextEntityManager;
   
   public static final Version v = Version.valueOf("LUCENE_31");

        @SuppressWarnings("unchecked")
   public List<Article> filterPhotoWithArticle(String filter) {
      try {
            String fields = new String("Article.commentaire");
            //Récupération d'un entitymanager compatible hibernate search
       fullTextEntityManager = Search.getFullTextEntityManager(em);
        
            org.apache.lucene.search.Query standardQuery = null;
            QueryParser parser = new QueryParser(v, fields, new StandardAnalyzer(v));
            try {
                standardQuery = parser.parse(filter);
            } catch (ParseException ex) {
                Logger.getLogger(Dao.class.getName()).log(Level.SEVERE, null, ex);
            }
           
            FullTextQuery persistenceQuery = fullTextEntityManager.createFullTextQuery(standardQuery, Article.class);
            return persistenceQuery.getResultList();
        } finally {
            em.close();
        }
   }



I hope someone can help me! I really don't see what's wrong :(
Thank you for your time!


Top
 Profile  
 
 Post subject: Re: Problem integrating Hibsearch in a Spring & hibernat/JPA App
PostPosted: Sun May 08, 2011 1:30 pm 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
Hi,
Quote:
Here are some .jar I use for this app:
hibernate3.jar
hibernate-annotations.jar
hibernate-entitymanager-3.2.1.ga.jar
hibernate-entitymanager.jar
spring-2.5.6.jar
lucene-core-3.1.0.jar
hibernate-core-3.6.4.Final.jar
hibernate-search-3.4.0.Final.jar
hibernate-search-infinispan-3.4.0.Final.jar

I think that's wrong: you're using hibernate-core-3.6.4.Final which is great, but you're also including very old libraries: you can't mix them.

This is the output from mvn dependency:tree from our Spring integration tests:
Code:
[INFO] org.hibernate:hibernate-search-integrationtest:jar:3.5.0-SNAPSHOT
[INFO] +- org.hibernate:hibernate-search:jar:3.5.0-SNAPSHOT:test
[INFO] |  +- org.hibernate:hibernate-search-analyzers:jar:3.5.0-SNAPSHOT:test
[INFO] |  |  +- org.apache.lucene:lucene-analyzers:jar:3.1.0:test
[INFO] |  |  \- org.apache.solr:solr-analysis-extras:jar:3.1.0:test
[INFO] |  |     +- org.apache.solr:solr-core:jar:3.1.0:test
[INFO] |  |     |  +- org.apache.solr:solr-solrj:jar:3.1.0:test
[INFO] |  |     |  +- org.apache.lucene:lucene-highlighter:jar:3.1.0:test
[INFO] |  |     |  +- org.apache.lucene:lucene-memory:jar:3.1.0:test
[INFO] |  |     |  +- org.apache.lucene:lucene-misc:jar:3.1.0:test
[INFO] |  |     |  +- org.apache.lucene:lucene-spatial:jar:3.1.0:test
[INFO] |  |     |  +- org.apache.lucene:lucene-spellchecker:jar:3.1.0:test
[INFO] |  |     |  +- org.apache.solr:solr-commons-csv:jar:3.1.0:test
[INFO] |  |     |  +- commons-io:commons-io:jar:1.4:test
[INFO] |  |     |  \- commons-lang:commons-lang:jar:2.4:test
[INFO] |  |     +- org.apache.lucene:lucene-smartcn:jar:3.1.0:test
[INFO] |  |     \- org.apache.lucene:lucene-stempel:jar:3.1.0:test
[INFO] |  +- org.hibernate:hibernate-core:jar:3.6.3.Final:test
[INFO] |  |  +- antlr:antlr:jar:2.7.6:test
[INFO] |  |  \- commons-collections:commons-collections:jar:3.1:test
[INFO] |  +- org.hibernate:hibernate-commons-annotations:jar:3.2.0.Final:test
[INFO] |  \- org.apache.lucene:lucene-core:jar:3.1.0:test
[INFO] +- org.hibernate:hibernate-search-testing:jar:3.5.0-SNAPSHOT:test
[INFO] |  \- org.hibernate:hibernate-search:test-jar:tests:3.5.0-SNAPSHOT:test
[INFO] +- org.hibernate:hibernate-entitymanager:jar:3.6.3.Final:test
[INFO] |  \- cglib:cglib:jar:2.2:test
[INFO] |     \- asm:asm:jar:3.1:test
[INFO] +- org.hibernate:hibernate-testing:jar:3.6.3.Final:test
[INFO] +- javassist:javassist:jar:3.12.1.GA:test
[INFO] +- junit:junit:jar:4.8.2:test
[INFO] +- org.springframework:spring-core:jar:3.0.5.RELEASE:test
[INFO] |  \- org.springframework:spring-asm:jar:3.0.5.RELEASE:test
[INFO] +- org.springframework:spring-aop:jar:3.0.5.RELEASE:test
[INFO] |  +- aopalliance:aopalliance:jar:1.0:test
[INFO] |  \- org.springframework:spring-beans:jar:3.0.5.RELEASE:test
[INFO] +- org.springframework:spring-orm:jar:3.0.5.RELEASE:test
[INFO] |  \- org.springframework:spring-jdbc:jar:3.0.5.RELEASE:test
[INFO] +- org.springframework:spring-context:jar:3.0.5.RELEASE:test
[INFO] |  \- org.springframework:spring-expression:jar:3.0.5.RELEASE:test
[INFO] +- org.springframework:spring-context-support:jar:3.0.5.RELEASE:test
[INFO] +- org.springframework:spring-tx:jar:3.0.5.RELEASE:test
[INFO] +- org.springframework:spring-test:jar:3.0.5.RELEASE:test
[INFO] +- javax.inject:javax.inject:jar:1.0-PFD-1:test
[INFO] +- org.codehaus.btm:btm:jar:2.1.0:test
[INFO] |  \- javax.transaction:jta:jar:1.1:provided
[INFO] +- com.h2database:h2:jar:1.3.153:test
[INFO] +- org.slf4j:slf4j-api:jar:1.6.1:compile

(most of them are optional, but check the versions and make sure you don't have duplicates)

To easily find duplicate classes, use this awesome tool : http://www.jboss.org/tattletale
It's a command line tool, doesn't require JBoss, it can scan any classloader/ directory and will tell you what classes you have duplicated and in which jars they are.

_________________
Sanne
http://in.relation.to/


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