我的POJO中有以下配置:
@Field(index = Index.NO, store = Store.YES)
private byte[] file;
启动我的Apps容器时,出现以下异常:
Caused by: org.hibernate.search.SearchException: Unable to guess FieldBridge for file
at org.hibernate.search.bridge.BridgeFactory.guessType(BridgeFactory.java:249)
at org.hibernate.search.engine.AbstractDocumentBuilder.bindFieldAnnotation(AbstractDocumentBuilder.java:707)
at org.hibernate.search.engine.AbstractDocumentBuilder.checkForField(AbstractDocumentBuilder.java:568)
at org.hibernate.search.engine.AbstractDocumentBuilder.initializeMemberLevelAnnotations(AbstractDocumentBuilder.java:436)
at org.hibernate.search.engine.AbstractDocumentBuilder.initializeClass(AbstractDocumentBuilder.java:383)
at org.hibernate.search.engine.AbstractDocumentBuilder.checkForIndexedEmbedded(AbstractDocumentBuilder.java:631)
at org.hibernate.search.engine.AbstractDocumentBuilder.initializeMemberLevelAnnotations(AbstractDocumentBuilder.java:440)
at org.hibernate.search.engine.AbstractDocumentBuilder.initializeClass(AbstractDocumentBuilder.java:383)
at org.hibernate.search.engine.AbstractDocumentBuilder.(AbstractDocumentBuilder.java:134)
at org.hibernate.search.engine.DocumentBuilderIndexedEntity.(DocumentBuilderIndexedEntity.java:178)
at org.hibernate.search.spi.SearchFactoryBuilder.initDocumentBuilders(SearchFactoryBuilder.java:375)
at org.hibernate.search.spi.SearchFactoryBuilder.buildNewSearchFactory(SearchFactoryBuilder.java:262)
at org.hibernate.search.spi.SearchFactoryBuilder.buildSearchFactory(SearchFactoryBuilder.java:144)
at org.hibernate.search.event.FullTextIndexEventListener.initialize(FullTextIndexEventListener.java:151)
at org.hibernate.event.EventListeners$1.processListener(EventListeners.java:198)
at org.hibernate.event.EventListeners.processListeners(EventListeners.java:181)
at org.hibernate.event.EventListeners.initializeListeners(EventListeners.java:194)
… 41 more
如何在Hibernate Search(Lucene)索引中存储字节数组?
解决方法:
您将需要一个field bridge.
例如:
@Field(index = Index.NO, store = Store.YES)
@FieldBridge(impl = MyFieldBridge.class)
private byte[] file;
//The file bridge
public class MyFieldBridge implements StringBridge {
@Override
public String objectToString(final Object object) {
byte[] file = (byte[]) object;
return MagicFileUtil.getTextContent(file)
}
}