Reputation: 590
Indexing of new elements not working with Hibernate + Spring. No errors are displayed in logs.
Hibernate and Spring versions:
Spring-context.xml
<bean id="dataSource" class="org.springframework.jdbc.datasource.LazyConnectionDataSourceProxy">
<property name="targetDataSource">
<ref local="mainDataSource" />
</property>
</bean>
<bean id="mainDataSource" class="com.jolbox.bonecp.BoneCPDataSource" destroy-method="close">
<property name="driverClass" value="${jdbc.driver}" />
<property name="jdbcUrl" value="${jdbc.url}" />
<property name="username" value="${jdbc.username}"/>
<property name="password" value="${jdbc.password}"/>
<property name="idleConnectionTestPeriodInMinutes" value="${jdbc.idleConnectionTestPeriodInMinutes}"/>
<property name="idleMaxAgeInMinutes" value="${jdbc.idleMaxAgeInMinutes}"/>
<property name="maxConnectionsPerPartition" value="${jdbc.maxConnectionsPerPartition}"/>
<property name="minConnectionsPerPartition" value="${jdbc.minConnectionsPerPartition}"/>
<property name="partitionCount" value="${jdbc.partitionCount}"/>
<property name="acquireIncrement" value="${jdbc.acquireIncrement}"/>
<property name="statementsCacheSize" value="${jdbc.statementsCacheSize}"/>
<property name="releaseHelperThreads" value="${jdbc.releaseHelperThreads}"/>
</bean>
<bean id="sessionFactory"
class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
<prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
<prop key="hibernate.hbm2ddl.auto">none</prop>
<prop key="hibernate.connection.release_mode">auto</prop>
<prop key="hibernate.auto_close_session">true</prop>
<prop key="hibernate.cache.use_query_cache">true</prop>
<prop key="hibernate.cache.use_second_level_cache">true</prop>
<prop key="hibernate.cache.use_query_cache">true</prop>
<prop key="hibernate.cache.region.factory_class">org.hibernate.cache.ehcache.SingletonEhCacheRegionFactory</prop>
<!-- Hibernate search - lucene -->
<prop key="hibernate.search.default.directory_provider">filesystem</prop>
<prop key="hibernate.search.default.indexBase">/temp/lucene</prop>
</props>
</property>
<property name="packagesToScan" value="com.example.domain" />
</bean>
<bean id="transactionManager"
class="org.springframework.orm.hibernate4.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<tx:annotation-driven transaction-manager="transactionManager" />
Code fragment of class to be indexed
@Indexed
@Entity
@Table(name = "table_name")
public class VideoInfo implements Serializable {
@Id
@Column(name = "id")
@GeneratedValue(strategy = GenerationType.AUTO)
private long id;
@Column(name = "title")
@Field(index=Index.YES, store=Store.NO)
private String title;
@Column(name = "tags")
@Field(index=Index.YES, store=Store.NO)
private String tags;
@Column(name = "url")
private String url;
....
DAO save method (factory === sessionFactory bean)
factory.getCurrentSession().save(obj);
What could be the problem? Right now I am just a bit confused of what I should actually do, so please help me :)
EDIT: Finally rebuilding the index things began to work properly.
Upvotes: 2
Views: 1026
Reputation: 19
I have the same problem but with hibernate 4.1, Envers and EJB 3. I solved it with the annotation @TransactionAttribute to managed the transaction. The Envers listener dont start if the transaction doesn't "normal end". I hope it will help (sorry for my english)
Upvotes: 2