是否有可能使用Hibernate搜索與休眠,但沒有jpa。 我只使用jpa註釋,但我不使用entityManager。休眠與冬眠搜索
在這種情況下,當我使用hibernate會話在db中創建一個新對象時,hibernate搜索如何知道他必須索引一個對象。
到目前爲止,我只有一個名爲「人」的實體。 我在此實體中添加了@indexed,現在我無法再更新數據庫中的人員實體。在更新此實體的事務期間調用session.flush時有一個例外。
thx很多。
這裏是我做的,到目前爲止,
我加入的hibernate.cfg.xml:
<property name="hibernate.search.default.directory_provider">
org.hibernate.search.store.FSDirectoryProvider
</property>
<property name="hibernate.search.default.indexBase">./lucene/indexes</property>
<property name="hibernate.search.default.batch.merge_factor">10</property>
<property name="hibernate.search.default.batch.max_buffered_docs">10</property>
<event type="post-update">
<listener class="org.hibernate.search.event.FullTextIndexEventListener"/>
</event>
<event type="post-insert">
<listener class="org.hibernate.search.event.FullTextIndexEventListener"/>
</event>
<event type="post-delete">
<listener class="org.hibernate.search.event.FullTextIndexEventListener"/>
</event>
假設下面的 「版本」 實體:
@Entity
@Indexed(index="indexes/versions")
@Table(name="VERSIONS")
public class Version implements Serializable {
@Id
@DocumentId
@GeneratedValue(strategy=GenerationType.AUTO)
@Column(name="V_NO", length=10)
private Integer valueNb;
@Column(nullable=false)
@Temporal(TemporalType.TIMESTAMP)
private Date tstamp;
這是保存版本的方法:
private Version performUpdateActualOnCreation(Session session, VersionedObject storedObject, String userId, String message) {
// create new version
Version version = new Version(userId, message);
session.save(version);
// update previous version do the object with the Next Value NB
if (storedObject != null) {
storedObject.setNextVersion(version);
session.update(storedObject);
} else {
logger.error("Error: trying to update versioned object which has no previous version!!");
}
session.flush();
return version;
}
問題出現在session.flush(); 這裏是堆棧跟蹤,但我沒有看到什麼inthere: (我也可以看到索引文件創建「索引/版本」,但它是空的)
DEBUG 2010-11-02 17:26:33,368+0100 http-8889-Processor6 com.data.server.dao.impl.HibernateDao.rollbackTransaction(HibernateDao.java:104) Rolling back Hibernate transaction
com.google.gwt.user.client.rpc.StatusCodeException: The call failed on the server; see server log for details
at com.google.gwt.user.client.rpc.impl.RequestCallbackAdapter.onResponseReceived(RequestCallbackAdapter.java:192)
at com.google.gwt.http.client.Request.fireOnResponseReceived(Request.java:287)
at com.google.gwt.http.client.RequestBuilder$1.onReadyStateChange(RequestBuilder.java:393)
at sun.reflect.GeneratedMethodAccessor50.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:103)
at com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:71)
at com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:157)
at com.google.gwt.dev.shell.BrowserChannel.reactToMessagesWhileWaitingForReturn(BrowserChannel.java:1713)
at com.google.gwt.dev.shell.BrowserChannelServer.invokeJavascript(BrowserChannelServer.java:165)
at com.google.gwt.dev.shell.ModuleSpaceOOPHM.doInvoke(ModuleSpaceOOPHM.java:120)
at com.google.gwt.dev.shell.ModuleSpace.invokeNative(ModuleSpace.java:507)
at com.google.gwt.dev.shell.ModuleSpace.invokeNativeObject(ModuleSpace.java:264)
at com.google.gwt.dev.shell.JavaScriptHost.invokeNativeObject(JavaScriptHost.java:91)
at com.google.gwt.core.client.impl.Impl.apply(Impl.java)
at com.google.gwt.core.client.impl.Impl.entry0(Impl.java:188)
at sun.reflect.GeneratedMethodAccessor44.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:103)
at com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:71)
at com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:157)
at com.google.gwt.dev.shell.BrowserChannel.reactToMessages(BrowserChannel.java:1668)
at com.google.gwt.dev.shell.BrowserChannelServer.processConnection(BrowserChannelServer.java:401)
at com.google.gwt.dev.shell.BrowserChannelServer.run(BrowserChannelServer.java:222)
at java.lang.Thread.run(Thread.java:619)
請更改休眠版本3.1.1 GA – 2017-05-24 01:06:13