我正在尝试将Hibernate Search集成到已经运行的Play Framework应用程序中。我有建立索引的问题,或者那就是我认为的问题。
我有一个用户:
var query = from a in addressRepository.GetAll() select a;
IList<AddressSearchResponseDto> result = Mapper.Map<IList<Address>, IList<AddressSearchResponseDto>>(query.ToList());
这是我的persistence.xml:
http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd” 版本= “2.0” &GT;
@Indexed
@Entity
public class User extends Model {
@Field
public String firstname;
@Field
public String lastname;
@Field
public String email;
}
因此,我认为索引的构建(对于数据库中已存在的数据)应该在GlobalAdmin对象的<persistence-unit name="default" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
<non-jta-data-source>DefaultDS</non-jta-data-source>
<class>models.User</class>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/>
<property name="hibernate.hbm2ddl.auto" value="update"/>
<property name="hibernate.search.default.directory_provider"
value="filesystem"/>
<property name="hibernate.search.default.indexBase"
value="/Users/<user>/lucene/indexes"/>
</properties>
</persistence-unit>
中进行。我使用onStart
来调用索引器:
JPA.withTransaction
问题是我得到了:
JPA.withTransaction(new F.Callback0() {
@Override
public void invoke() throws Throwable {
FullTextEntityManager fullTextEntityManager = org.hibernate.search.jpa.Search.getFullTextEntityManager(JPA.em());
try {
fullTextEntityManager.createIndexer().startAndWait();
} catch (Exception e) {
Logger.error(e.getMessage());
}
}
});
感谢您的帮助。
编辑:
我在控制器中的搜索方法:
正如在建议的评论中,我在'onStart'中取消注释了Indexer。
[error] o.h.e.j.s.SqlExceptionHelper - Timed out waiting for a free available connection.
[error] o.h.s.e.i.LogErrorHandler - HSEARCH000058: HSEARCH000211: An exception occurred while the MassIndexer was fetching the primary identifiers list
org.hibernate.exception.JDBCConnectionException: Could not open connection
at org.hibernate.exception.internal.SQLStateConversionDelegate.convert(SQLStateConversionDelegate.java:132) ~[hibernate-core-4.3.9.Final.jar:4.3.9.Final]
at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:49) ~[hibernate-core-4.3.9.Final.jar:4.3.9.Final]
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:126) ~[hibernate-core-4.3.9.Final.jar:4.3.9.Final]
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:112) ~[hibernate-core-4.3.9.Final.jar:4.3.9.Final]
at org.hibernate.engine.jdbc.internal.LogicalConnectionImpl.obtainConnection(LogicalConnectionImpl.java:235) ~[hibernate-core-4.3.9.Final.jar:4.3.9.Final]
Caused by: java.sql.SQLException: Timed out waiting for a free available connection.
at com.jolbox.bonecp.DefaultConnectionStrategy.getConnectionInternal(DefaultConnectionStrategy.java:88) ~[bonecp-0.8.0.RELEASE.jar:na]
at com.jolbox.bonecp.AbstractConnectionStrategy.getConnection(AbstractConnectionStrategy.java:90) ~[bonecp-0.8.0.RELEASE.jar:na]
at com.jolbox.bonecp.BoneCP.getConnection(BoneCP.java:553) ~[bonecp-0.8.0.RELEASE.jar:na]
at com.jolbox.bonecp.BoneCPDataSource.getConnection(BoneCPDataSource.java:131) ~[bonecp-0.8.0.RELEASE.jar:na]
at org.hibernate.engine.jdbc.connections.internal.DatasourceConnectionProviderImpl.getConnection(DatasourceConnectionProviderImpl.java:139) ~[hibernate-core-4.3.9.Final.jar:4.3.9.Final]
这是我第一次尝试使用Hibernate Search的方法。但是,这不会返回任何内容。
答案 0 :(得分:1)
您的问题似乎不在于直接搜索。看看堆栈跟踪,似乎你的JDBC连接已经用完了。我自己不认识BoneCP,但它似乎是一个JDBC池库。你的配置是什么?您是否尝试过增加连接池大小?