Welcome!
I have searched a lot (Google and this discussion board,
https://www.hibernate.org/441.html), tried lots of old hibernate and spring versions, and still I cannot make it work correctly. Everything seems to work fine except reindexing on update relation entity. I think it might be an issue associated with executing FullTextIndexEventListener.
My example is the authors<->books application. I do the following in my index test case:
Code:
AuthorDAO authorDAO = (AuthorDAO) ctx.getBean("authorDAOImpl");
AuthorEntity a = new AuthorEntity();
a.setFirstName("author");
a.setLastName("author");
authorDAO.saveAuthor(a);
BookDAO bookDAO = (BookDAO) ctx.getBean("bookDAOImpl");
BookEntity b = new BookEntity();
b.setTitle("title");
b.setPublicationDate(new Date());
b.setContent("content");
Set<AuthorEntity> authors = new HashSet<AuthorEntity>();
authors.add(a);
b.setAuthors(authors);
bookDAO.saveBook(b);
// Everything ok here. Indexed data is correct.
a.setFirstName("Changed"); // Changing value.
authorDAO.saveAuthor(a); // Here the authors.firstName index property is not being reindexed
Library versions:
Hibernate 3.3.2.GA
Hibernate Search 3.1.1.GA
Hibernate Annotations 3.4.0.GA
Spring 2.5.6.SEC01
My code:
Spring configuration:
Code:
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations" value="classpath:jdbc.properties"/>
</bean>
<bean id="dataSource" destroy-method="close" class="org.apache.commons.dbcp.BasicDataSource"
init-method="createDataSource">
<property name="driverClassName" value="${jdbc.driverClassName}"/>
<property name="url" value="${jdbc.url}"/>
<property name="username" value="${jdbc.username}"/>
<property name="password" value="${jdbc.password}"/>
</bean>
<bean id="hibernateSessionFactory"
class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="schemaUpdate" value="true"/>
<property name="hibernateProperties">
<value>
hibernate.dialect = org.hibernate.dialect.DataDirectOracle9Dialect
hibernate.hbm2ddl.auto = create
hibernate.show_sql = true
hibernate.format_sql = false
hibernate.search.default.directory_provider = org.hibernate.search.store.FSDirectoryProvider
hibernate.search.default.indexBase = C:\index\
</value>
</property>
<property name="annotatedClasses">
<list>
<value>edu.lantoniak.hibernate.search.model.AuthorEntity</value>
<value>edu.lantoniak.hibernate.search.model.BookEntity</value>
</list>
</property>
</bean>
<bean id="authorDAOImpl" class="edu.lantoniak.hibernate.search.dao.AuthorDAOImpl">
<property name="sessionFactory" ref="hibernateSessionFactory"/>
</bean>
<bean id="bookDAOImpl" class="edu.lantoniak.hibernate.search.dao.BookDAOImpl">
<property name="sessionFactory" ref="hibernateSessionFactory"/>
</bean>
DAO implementation:
Code:
public class BookDAOImpl extends HibernateDaoSupport implements BookDAO {
public void saveBook(BookEntity b) {
getHibernateTemplate().saveOrUpdate(b);
}
}
Mappings:
Code:
@Entity
@javax.persistence.SequenceGenerator(name="BOOKS_SEQ_GEN", sequenceName="BOOKS_SEQ")
@Table(name="BOOKS")
@Indexed
public class BookEntity {
...
@ManyToMany(targetEntity=AuthorEntity.class)
@JoinTable(name="AUTHORS_BOOKS", joinColumns=@JoinColumn(name="BOOKS_ID"), inverseJoinColumns=@JoinColumn(name="AUTHORS_ID"))
@IndexedEmbedded(depth=1)
public Set<AuthorEntity> getAuthors() {
return authors;
}
...
}
Code:
@Entity
@javax.persistence.SequenceGenerator(name="AUTHORS_SEQ_GEN", sequenceName="AUTHORS_SEQ")
@Table(name="AUTHORS")
@Indexed
public class AuthorEntity {
...
@ManyToMany(mappedBy="authors", targetEntity=BookEntity.class)
@ContainedIn
public Set<BookEntity> getBooks() {
return books;
}
...
}
I have tried getHibernateTemplate().setExposeNativeSession(true); before savOrUpdate, and explicite registering eventListners but it did not help.
I will be very grateful for any help.
Regards,
Lukasz
Edit: I have tried also playing with:
Code:
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="hibernateSessionFactory"/>
</bean>
<tx:annotation-driven transaction-manager="transactionManager"/>
@Transactional(propagation=Propagation.REQUIRED)
public void saveBook(BookEntity b) {
getHibernateTemplate().saveOrUpdate(b);
}
But still nothing happens.