-->
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: Hibernate Search and Spring - Index empty
PostPosted: Sun Jun 13, 2010 10:01 pm 
Newbie

Joined: Sun Jun 13, 2010 9:35 pm
Posts: 1
I'm having a problem where Hibernate-search is not persisting fields, since the Lucene index is empty.

I have already researched this forum, and found clues about transactions being related to the problem.
Yet all posts are using much earlier versions of Spring and Hibernate-search.
I'm not sure what to try next... Please help!

I'm using the following versions of Hibernate and Spring:

<hibernate-search-version>3.2.0.Final</hibernate-search-version>
<hibernate-validator-version>4.0.2.GA</hibernate-validator-version>
<hibernate-annotations-version>3.3.1.GA</hibernate-annotations-version>
<springframework-version>3.0.2.RELEASE</springframework-version>

My Configuration is as follows:

app-context.xml:

<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:jee="http://www.springframework.org/schema/jee"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/b ... ns-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/c ... xt-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/t ... tx-3.0.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/j ... 22-3.0.xsd">

<context:property-placeholder location="classpath:jdbc.properties"/>
<context:annotation-config/>
<context:component-scan base-package="net.resumage.core"/>

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

<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager" p:entityManagerFactory-ref="entityManagerFactory"/>

<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"
p:dataSource-ref="dataSource"
p:jpaVendorAdapter-ref="jpaAdapter">
<property name="loadTimeWeaver">
<bean class="org.springframework.instrument.classloading.InstrumentationLoadTimeWeaver"/>
</property>
<property name="persistenceUnitName" value="resumage"></property>
</bean>

<bean id="jpaAdapter" class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"
p:database="${jpa.database}"
p:showSql="${jpa.showSql}"
p:generateDdl="${jpa.generateDdl}"/>

//embedded data-source for now
<jdbc:embedded-database id="dataSource"></jdbc:embedded-database>

<tx:annotation-driven transaction-manager="transactionManager"/>
</beans>


Then my Persistence.xml is

<persistence 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/ ... ce_1_0.xsd"
version="1.0">
<persistence-unit name="resumage" transaction-type="RESOURCE_LOCAL">

<!--todo: set ORM.xml file or figure out how to auto scan it-->
<class>net.resumage.core.domain.Resume</class>
<class>net.resumage.core.domain.ResumePoster</class>
<exclude-unlisted-classes>true</exclude-unlisted-classes>
<properties>
<!--Hibernate Search Configuration-->
<property name="hibernate.search.default.directory_provider" value="org.hibernate.search.store.FSDirectoryProvider"/>
<property name="hibernate.search.default.indexBase" value="/tmp/resumage/indexes"></property>
<!--Hibernate Properties-->
<property name="hibernate.generate_statistics" value="true"/>
<property name="hibernate.cache.use_structured_entries" value="true"/>
<property name="hibernate.format_sql" value="false"/>
<property name="hibernate.use_sql_comments" value="false"/>
<property name="hibernate.jdbc.batch_size" value="30"/>
</properties>
</persistence-unit>
</persistence>


This is my test file:

@ContextConfiguration(locations = {"domainTest-context.xml"})
@RunWith(SpringJUnit4ClassRunner.class)
public class ResumePosterHibernateSearchTests
{
@PersistenceContext
private EntityManager em;
private ResumePoster resumePoster;
private Resume resume;


@Test
@Transactional
public void testFindIndexedPlainTextContent() throws ParseException
{
QueryParser parser = new QueryParser(Version.LUCENE_29, "plainTextContent", new StandardAnalyzer(Version.LUCENE_29));
String searchQuery = "plainTextContent:plain";
org.apache.lucene.search.Query luceneQuery = parser.parse(searchQuery);

FullTextEntityManager ftem = getFullTextEntityManager(em);

// attempt to explicit index - does not work either
// Resume reference = em.getReference(Resume.class, resume.getId());
// ftem.index(reference);
// ftem.flush();

FullTextQuery textQuery = ftem.createFullTextQuery(luceneQuery, Resume.class);
List resultList = textQuery.getResultList();
assertEquals(1, resultList.size());
assertEquals(resumePoster, resultList.iterator().next());
}

@Transactional
@Before
public void setup()
{
resumePoster = new ResumePoster();
resumePoster.setEmailAddress("bogus@gmail.com");
resume = new Resume();
resume.setPlainTextContent("this is plain text content phrase for testing purposes");
resumePoster.addResume(resume);
em.persist(resumePoster);
em.flush();
em.clear();
}


My test fails because it does not find the indexed content. Using Luke I can confirm no documents are there.


here is my log,


2010-06-13 18:48:30,031 INFO [org.hibernate.cfg.AnnotationBinder] - <Binding entity from annotated class: net.resumage.core.domain.Resume>
2010-06-13 18:48:30,062 INFO [org.hibernate.cfg.annotations.EntityBinder] - <Bind entity net.resumage.core.domain.Resume on table Resume>
2010-06-13 18:48:30,093 INFO [org.hibernate.cfg.AnnotationBinder] - <Binding entity from annotated class: net.resumage.core.domain.ResumePoster>
2010-06-13 18:48:30,093 INFO [org.hibernate.cfg.annotations.EntityBinder] - <Bind entity net.resumage.core.domain.ResumePoster on table ResumePoster>
2010-06-13 18:48:30,140 INFO [org.hibernate.cfg.annotations.CollectionBinder] - <Mapping collection: net.resumage.core.domain.ResumePoster.resumes -> Resume>
2010-06-13 18:48:30,140 INFO [org.hibernate.cfg.AnnotationConfiguration] - <Hibernate Validator not found: ignoring>
2010-06-13 18:48:30,156 INFO [org.hibernate.validator.util.Version] - <Hibernate Validator 4.0.2.GA>
2010-06-13 18:48:30,156 INFO [org.hibernate.validator.engine.resolver.DefaultTraversableResolver] - <Instantiated an instance of org.hibernate.validator.engine.resolver.JPATraversableResolver.>
2010-06-13 18:48:30,218 INFO [org.hibernate.validator.engine.resolver.DefaultTraversableResolver] - <Instantiated an instance of org.hibernate.validator.engine.resolver.JPATraversableResolver.>
2010-06-13 18:48:30,218 INFO [org.hibernate.validator.engine.resolver.DefaultTraversableResolver] - <Instantiated an instance of org.hibernate.validator.engine.resolver.JPATraversableResolver.>
2010-06-13 18:48:30,234 INFO [org.hibernate.connection.ConnectionProviderFactory] - <Initializing connection provider: org.hibernate.ejb.connection.InjectedDataSourceConnectionProvider>
2010-06-13 18:48:30,234 INFO [org.hibernate.ejb.connection.InjectedDataSourceConnectionProvider] - <Using provided datasource>
2010-06-13 18:48:30,390 INFO [org.hibernate.cfg.SettingsFactory] - <RDBMS: HSQL Database Engine, version: 1.8.0>
2010-06-13 18:48:30,390 INFO [org.hibernate.cfg.SettingsFactory] - <JDBC driver: HSQL Database Engine Driver, version: 1.8.0>
2010-06-13 18:48:30,406 INFO [org.hibernate.dialect.Dialect] - <Using dialect: org.hibernate.dialect.HSQLDialect>
2010-06-13 18:48:30,406 INFO [org.hibernate.engine.jdbc.JdbcSupportLoader] - <Disabling contextual LOB creation as JDBC driver reported JDBC version [3] less than 4>
2010-06-13 18:48:30,406 INFO [org.hibernate.transaction.TransactionFactoryFactory] - <Transaction strategy: org.hibernate.transaction.JDBCTransactionFactory>
2010-06-13 18:48:30,406 INFO [org.hibernate.transaction.TransactionManagerLookupFactory] - <No TransactionManagerLookup configured (in JTA environment, use of read-write or transactional second-level cache is not recommended)>
2010-06-13 18:48:30,406 INFO [org.hibernate.cfg.SettingsFactory] - <Automatic flush during beforeCompletion(): disabled>
2010-06-13 18:48:30,406 INFO [org.hibernate.cfg.SettingsFactory] - <Automatic session close at end of transaction: disabled>
2010-06-13 18:48:30,406 INFO [org.hibernate.cfg.SettingsFactory] - <JDBC batch size: 30>
2010-06-13 18:48:30,406 INFO [org.hibernate.cfg.SettingsFactory] - <JDBC batch updates for versioned data: disabled>
2010-06-13 18:48:30,406 INFO [org.hibernate.cfg.SettingsFactory] - <Scrollable result sets: enabled>
2010-06-13 18:48:30,406 INFO [org.hibernate.cfg.SettingsFactory] - <JDBC3 getGeneratedKeys(): disabled>
2010-06-13 18:48:30,406 INFO [org.hibernate.cfg.SettingsFactory] - <Connection release mode: auto>
2010-06-13 18:48:30,406 INFO [org.hibernate.cfg.SettingsFactory] - <Default batch fetch size: 1>
2010-06-13 18:48:30,406 INFO [org.hibernate.cfg.SettingsFactory] - <Generate SQL with comments: disabled>
2010-06-13 18:48:30,406 INFO [org.hibernate.cfg.SettingsFactory] - <Order SQL updates by primary key: disabled>
2010-06-13 18:48:30,406 INFO [org.hibernate.cfg.SettingsFactory] - <Order SQL inserts for batching: disabled>
2010-06-13 18:48:30,421 INFO [org.hibernate.cfg.SettingsFactory] - <Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory>
2010-06-13 18:48:30,421 INFO [org.hibernate.hql.ast.ASTQueryTranslatorFactory] - <Using ASTQueryTranslatorFactory>
2010-06-13 18:48:30,421 INFO [org.hibernate.cfg.SettingsFactory] - <Query language substitutions: {}>
2010-06-13 18:48:30,421 INFO [org.hibernate.cfg.SettingsFactory] - <JPA-QL strict compliance: enabled>
2010-06-13 18:48:30,421 INFO [org.hibernate.cfg.SettingsFactory] - <Second-level cache: enabled>
2010-06-13 18:48:30,421 INFO [org.hibernate.cfg.SettingsFactory] - <Query cache: disabled>
2010-06-13 18:48:30,421 INFO [org.hibernate.cfg.SettingsFactory] - <Cache region factory : org.hibernate.cache.impl.NoCachingRegionFactory>
2010-06-13 18:48:30,421 INFO [org.hibernate.cfg.SettingsFactory] - <Optimize cache for minimal puts: disabled>
2010-06-13 18:48:30,421 INFO [org.hibernate.cfg.SettingsFactory] - <Structured second-level cache entries: enabled>
2010-06-13 18:48:30,421 INFO [org.hibernate.cfg.SettingsFactory] - <Echoing all SQL to stdout>
2010-06-13 18:48:30,421 INFO [org.hibernate.cfg.SettingsFactory] - <Statistics: enabled>
2010-06-13 18:48:30,421 INFO [org.hibernate.cfg.SettingsFactory] - <Deleted entity synthetic identifier rollback: disabled>
2010-06-13 18:48:30,421 INFO [org.hibernate.cfg.SettingsFactory] - <Default entity-mode: pojo>
2010-06-13 18:48:30,421 INFO [org.hibernate.cfg.SettingsFactory] - <Named query checking : enabled>
2010-06-13 18:48:30,421 INFO [org.hibernate.cfg.SettingsFactory] - <Check Nullability in Core (should be disabled when Bean Validation is on): disabled>
2010-06-13 18:48:30,437 INFO [org.hibernate.search.Version] - <Hibernate Search 3.2.0.Final>
2010-06-13 18:48:30,453 DEBUG [org.hibernate.search.impl.InitContext] - <Using default similarity implementation: org.apache.lucene.search.DefaultSimilarity>
2010-06-13 18:48:30,515 DEBUG [org.hibernate.search.engine.DocumentBuilderIndexedEntity] - <Field selection in projections is set to true for entity net.resumage.core.domain.Resume.>
2010-06-13 18:48:30,515 DEBUG [org.hibernate.search.engine.DocumentBuilderIndexedEntity] - <Field selection in projections is set to true for entity net.resumage.core.domain.ResumePoster.>
2010-06-13 18:48:30,578 DEBUG [org.hibernate.search.event.FullTextIndexEventListener] - <Hibernate Search event listeners activated>
2010-06-13 18:48:30,578 DEBUG [org.hibernate.search.event.FullTextIndexEventListener] - <Hibernate Search event listeners activated>
2010-06-13 18:48:30,578 DEBUG [org.hibernate.search.event.FullTextIndexEventListener] - <Hibernate Search event listeners activated>
2010-06-13 18:48:30,578 DEBUG [org.hibernate.search.event.FullTextIndexEventListener] - <Hibernate Search event listeners activated>
2010-06-13 18:48:30,578 DEBUG [org.hibernate.search.event.FullTextIndexEventListener] - <Hibernate Search event listeners activated>
2010-06-13 18:48:30,578 DEBUG [org.hibernate.search.event.FullTextIndexEventListener] - <Hibernate Search event listeners activated>
2010-06-13 18:48:30,578 DEBUG [org.hibernate.search.event.FullTextIndexEventListener] - <Hibernate Search event listeners activated>
2010-06-13 18:48:30,578 INFO [org.hibernate.impl.SessionFactoryImpl] - <building session factory>
2010-06-13 18:48:30,703 INFO [org.hibernate.impl.SessionFactoryObjectFactory] - <Not binding factory to JNDI, no JNDI name configured>
2010-06-13 18:48:30,703 INFO [org.hibernate.tool.hbm2ddl.SchemaUpdate] - <Running hbm2ddl schema update>
2010-06-13 18:48:30,703 INFO [org.hibernate.tool.hbm2ddl.SchemaUpdate] - <fetching database metadata>
2010-06-13 18:48:30,718 INFO [org.hibernate.tool.hbm2ddl.SchemaUpdate] - <updating schema>
2010-06-13 18:48:30,718 INFO [org.hibernate.validator.engine.resolver.DefaultTraversableResolver] - <Instantiated an instance of org.hibernate.validator.engine.resolver.JPATraversableResolver.>
2010-06-13 18:48:30,734 INFO [org.hibernate.tool.hbm2ddl.DatabaseMetadata] - <table not found: Resume>
2010-06-13 18:48:30,734 INFO [org.hibernate.tool.hbm2ddl.DatabaseMetadata] - <table not found: ResumePoster>
2010-06-13 18:48:30,734 INFO [org.hibernate.tool.hbm2ddl.DatabaseMetadata] - <table not found: Resume>
2010-06-13 18:48:30,734 INFO [org.hibernate.tool.hbm2ddl.DatabaseMetadata] - <table not found: ResumePoster>
2010-06-13 18:48:30,734 INFO [org.hibernate.tool.hbm2ddl.SchemaUpdate] - <schema update complete>
2010-06-13 18:48:30,828 DEBUG [org.springframework.orm.jpa.JpaTransactionManager] - <Creating new transaction with name [testFindIndexedPlainTextContent]: PROPAGATION_REQUIRED,ISOLATION_DEFAULT; ''>
2010-06-13 18:48:30,843 DEBUG [org.springframework.orm.jpa.JpaTransactionManager] - <Opened new EntityManager [org.hibernate.ejb.EntityManagerImpl@13a1778] for JPA transaction>
2010-06-13 18:48:30,875 DEBUG [org.springframework.orm.jpa.JpaTransactionManager] - <Exposing JPA transaction as JDBC transaction [org.springframework.orm.jpa.vendor.HibernateJpaDialect$HibernateConnectionHandle@1a6b16f]>
2010-06-13 18:48:30,875 INFO [org.springframework.test.context.transaction.TransactionalTestExecutionListener] - <Began transaction (1): transaction manager [org.springframework.orm.jpa.JpaTransactionManager@127ff0d]; rollback [true]>
2010-06-13 18:48:30,906 DEBUG [org.hibernate.SQL] - <insert into ResumePoster (resume_poster_id, created, emailAddress, version) values (null, ?, ?, ?)>
Hibernate: insert into ResumePoster (resume_poster_id, created, emailAddress, version) values (null, ?, ?, ?)
2010-06-13 18:48:30,921 DEBUG [org.hibernate.SQL] - <call identity()>
Hibernate: call identity()
2010-06-13 18:48:30,921 DEBUG [org.hibernate.SQL] - <insert into Resume (resume_id, created, plainTextContent, resume_poster_id, searchable, version) values (null, ?, ?, ?, ?, ?)>
Hibernate: insert into Resume (resume_id, created, plainTextContent, resume_poster_id, searchable, version) values (null, ?, ?, ?, ?, ?)
2010-06-13 18:48:30,921 DEBUG [org.hibernate.SQL] - <call identity()>
Hibernate: call identity()
2010-06-13 18:48:30,968 DEBUG [org.hibernate.SQL] - <select resume0_.resume_id as resume1_0_0_, resume0_.created as created0_0_, resume0_.plainTextContent as plainTex3_0_0_, resume0_.resume_poster_id as resume6_0_0_, resume0_.searchable as searchable0_0_, resume0_.version as version0_0_ from Resume resume0_ where resume0_.resume_id=?>
Hibernate: select resume0_.resume_id as resume1_0_0_, resume0_.created as created0_0_, resume0_.plainTextContent as plainTex3_0_0_, resume0_.resume_poster_id as resume6_0_0_, resume0_.searchable as searchable0_0_, resume0_.version as version0_0_ from Resume resume0_ where resume0_.resume_id=?
2010-06-13 18:48:31,000 DEBUG [org.hibernate.search.reader.SharingBufferReaderProvider] - <Opening IndexReader for directoryProviders: 1>
2010-06-13 18:48:31,015 DEBUG [org.hibernate.search.reader.SharingBufferReaderProvider] - <Closing MultiReader: org.hibernate.search.reader.CacheableMultiReader@196bac4>
2010-06-13 18:48:31,015 DEBUG [org.springframework.orm.jpa.JpaTransactionManager] - <Initiating transaction rollback>
2010-06-13 18:48:31,015 DEBUG [org.springframework.orm.jpa.JpaTransactionManager] - <Rolling back JPA transaction on EntityManager [org.hibernate.ejb.EntityManagerImpl@13a1778]>
2010-06-13 18:48:31,015 DEBUG [org.springframework.orm.jpa.JpaTransactionManager] - <Closing JPA EntityManager [org.hibernate.ejb.EntityManagerImpl@13a1778] after transaction>
2010-06-13 18:48:31,015 DEBUG [org.springframework.orm.jpa.EntityManagerFactoryUtils] - <Closing JPA EntityManager>
2010-06-13 18:48:31,015 INFO [org.springframework.test.context.transaction.TransactionalTestExecutionListener] - <Rolled back transaction after test execution for test context [[TestContext@1a9bea3 testClass = ResumePosterHibernateSearchTests, locations = array<String>['classpath:/net/resumage/core/domain/domainTest-context.xml'], testInstance = net.resumage.core.domain.ResumePosterHibernateSearchTests@122cc7e, testMethod = testFindIndexedPlainTextContent@ResumePosterHibernateSearchTests, testException = java.lang.AssertionError: expected:<1> but was:<0>]]>
2010-06-13 18:48:31,015 INFO [org.springframework.context.support.GenericApplicationContext] - <Closing org.springframework.context.support.GenericApplicationContext@1abab88: startup date [Sun Jun 13 18:48:29 PDT 2010]; root of context hierarchy>
2010-06-13 18:48:31,031 INFO [org.springframework.beans.factory.support.DefaultListableBeanFactory] - <Destroying singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@1313906: defining beans [org.springframework.beans.factory.config.PropertyPlaceholderConfigurer#0,org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,org.springframework.context.annotation.internalPersistenceAnnotationProcessor,luceneVersionConfig,org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor#0,transactionManager,entityManagerFactory,jpaAdapter,org.springframework.aop.config.internalAutoProxyCreator,org.springframework.transaction.annotation.AnnotationTransactionAttributeSource#0,org.springframework.transaction.interceptor.TransactionInterceptor#0,org.springframework.transaction.config.internalTransactionAdvisor,dataSource,luceneVersion]; root of factory hierarchy>
2010-06-13 18:48:31,031 INFO [org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean] - <Closing JPA EntityManagerFactory for persistence unit 'resumage'>
2010-06-13 18:48:31,031 INFO [org.hibernate.impl.SessionFactoryImpl] - <closing>

Process finished with exit code -1

java.lang.AssertionError: expected:<1> but was:<0>
at org.junit.Assert.fail(Assert.java:91)
at org.junit.Assert.failNotEquals(Assert.java:645)


Top
 Profile  
 
 Post subject: Re: Hibernate Search and Spring - Index empty
PostPosted: Wed Jun 23, 2010 5:49 pm 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
hello, I'm not a Spring expert but every time someone reports such an error we find out that the transactions configuration is wrong; please check that the transactions are setup correctly (try using JTA transactions?)

http://community.jboss.org/wiki/SpringHibernateHibernateSearch

in your setup() method you shouldn't flush and clear the em before the commit: keep in mind the indexes are updated at transaction commit.

also please note there's a dedicated forum area for Hibernate Search.

_________________
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.