我目前正在大学撰写论文,主题是将搜索功能集成到现有的Web应用程序中,并希望使用Hibernate Search。
但我正在努力解决现有应用程序中的实体索引问题。 似乎索引不起作用,因为在创建新实体时不会生成索引文件。此外,当我启动应用程序时,不会创建在休眠配置中配置的基本索引目录。 该应用程序将Spring Framework和Hibernate Core与hibernate-jpa 2.0一起使用(参见pom.xml)。
执行应用程序时没有错误,但有关于Hibernate Search的信息
INFO AnnotationSessionFactoryBean:780 - Building new Hibernate SessionFactory
INFO HibernateSearchEventListenerRegister:75 - Unable to find org.hibernate.search.event.FullTextIndexEventListener on the classpath. Hibernate Search is not enabled.
我读到在使用hibernate注释时我不需要集成这些监听器,所以这不能成为问题的根源,对吧?
从pom.xml中提取
<dependencies>
...
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>${hibernate.version}</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-envers</artifactId>
<version>${hibernate.version}</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>${hibernate-validator.version}</version>
</dependency>
<dependency>
<groupId>org.hibernate.javax.persistence</groupId>
<artifactId>hibernate-jpa-2.0-api</artifactId>
<version>1.0.1.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-search-orm</artifactId>
<version>4.3.0.Final</version>
</dependency>
</dependencies>
从applicationContext.xml中提取
<!-- Configuration of Hibernate Session -->
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="packagesToScan" value="de.user.server.model" />
<property name="hibernateProperties">
<props>
<prop key="hibernate.hbm2ddl.auto">update</prop>
<prop key="hibernate.show_sql">${jdbc.debug}</prop>
<prop key="hibernate.format_sql">true</prop>
<prop key="hibernate.id.new_generator_mappings">true</prop>
<prop key="hibernate.dialect">${jdbc.dialect}</prop>
<prop key="hibernate.jdbc.batch_size">0</prop>
<prop key="hibernate.hbm2ddl.import_files">import.sql</prop>
<prop key="hibernate.c3p0.idle_test_period">28680</prop>
<prop key="hibernate.search.default.directory_provider">filesystem</prop>
<prop key="hibernate.search.default.indexBase">H:/indexes</prop>
</props>
</property>
<!-- hibernate-envers for versioning of entities -->
<property name="eventListeners">
<map>
<entry key="post-insert" value-ref="envers" />
<entry key="post-update" value-ref="envers" />
<entry key="post-delete" value-ref="envers" />
<entry key="pre-collection-update" value-ref="envers" />
<entry key="pre-collection-remove" value-ref="envers" />
<entry key="post-collection-recreate" value-ref="envers" />
</map>
</property>
</bean>
Text.java
@Entity
@Indexed
@Connectable(modelClass = ModelClassEnum.TEXT)
public class Text extends AbstractDataObject {
/**
* Value generated automatically by eclipse.
*/
private static final long serialVersionUID = 8096234710520978913L;
private String text;
public Text() {
}
@Lob
@Field (name="text",index=Index.YES, analyze=Analyze.YES,store=Store.YES)
public String getText() {
return this.text;
}
public void setText(String text) {
this.text = text;
}
}
AbstractDataObject.java
@Entity
@Audited
@Inheritance(strategy = InheritanceType.JOINED)
public class AbstractDataObject extends BaseDomainModel {
private Long objectId;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@DocumentId
public Long getObjectId() {
return objectId;
}
}
我期待着你的回答。
亲切的问候, hbsnovice