我正在使用JPA和hibernate。然后将数据导入Solr。我在表中使用UUID作为id。问题是每当我尝试导入数据时,Solr都会抛出以下异常:
org.apache.solr.common.SolrException: TransactionLog doesn't know how to serialize class java.util.UUID; try implementing ObjectResolver?
solr | at org.apache.solr.update.TransactionLog$1.resolve(TransactionLog.java:100)
solr | at org.apache.solr.common.util.JavaBinCodec.writeVal(JavaBinCodec.java:234)
solr | at org.apache.solr.common.util.JavaBinCodec.writeSolrInputDocument(JavaBinCodec.java:589)
solr | at org.apache.solr.update.TransactionLog.write(TransactionLog.java:361)
solr | at org.apache.solr.update.UpdateLog.add(UpdateLog.java:482)
solr | at org.apache.solr.update.UpdateLog.add(UpdateLog.java:468)
solr | at org.apache.solr.update.DirectUpdateHandler2.doNormalUpdate(DirectUpdateHandler2.java:299)
solr | at org.apache.solr.update.DirectUpdateHandler2.addDoc0(DirectUpdateHandler2.java:211)
solr | at org.apache.solr.update.DirectUpdateHandler2.addDoc(DirectUpdateHandler2.java:166)
solr | at org.apache.solr.update.processor.RunUpdateProcessor.processAdd(RunUpdateProcessorFactory.java:67)
solr | at org.apache.solr.update.processor.UpdateRequestProcessor.processAdd(UpdateRequestProcessor.java:48)
solr | at org.apache.solr.update.processor.DistributedUpdateProcessor.doLocalAdd(DistributedUpdateProcessor.java:955)
solr | at org.apache.solr.update.processor.DistributedUpdateProcessor.versionAdd(DistributedUpdateProcessor.java:1110)
solr | at org.apache.solr.update.processor.DistributedUpdateProcessor.processAdd(DistributedUpdateProcessor.java:736)
solr | at org.apache.solr.update.processor.LogUpdateProcessorFactory$LogUpdateProcessor.processAdd(LogUpdateProcessorFactory.java:103)
solr | at org.apache.solr.handler.dataimport.SolrWriter.upload(SolrWriter.java:74)
solr | at org.apache.solr.handler.dataimport.DataImportHandler$1.upload(DataImportHandler.java:254)
solr | at org.apache.solr.handler.dataimport.DocBuilder.buildDocument(DocBuilder.java:526)
solr | at org.apache.solr.handler.dataimport.DocBuilder.buildDocument(DocBuilder.java:414)
solr | at org.apache.solr.handler.dataimport.DocBuilder.doDelta(DocBuilder.java:363)
solr | at org.apache.solr.handler.dataimport.DocBuilder.execute(DocBuilder.java:224)
solr | at org.apache.solr.handler.dataimport.DataImporter.doDeltaImport(DataImporter.java:444)
solr | at org.apache.solr.handler.dataimport.DataImporter.runCmd(DataImporter.java:477)
solr | at org.apache.solr.handler.dataimport.DataImporter.lambda$runAsync$0(DataImporter.java:458)
solr | at java.lang.Thread.run(Thread.java:745)
我的XML配置:
<requestHandler name="/dataimport" class="org.apache.solr.handler.dataimport.DataImportHandler">
<lst name="defaults">
<str name="config">DIHconfigfile.xml</str>
<str name="update.chain">uuid</str>
<!--<str name="update.chain">uuid</str>-->
<lst name="datasource">
<str name="type">JdbcDataSource</str>
<str name="readOnly">true</str>
<str name="autoCommit">false</str>
<str name="transactionIsolation">TRANSACTION_READ_COMMITTED</str>
<str name="holdability">CLOSE_CURSORS_AT_COMMIT</str>
<!-- <str name="batchSize">1000</str> -->
<str name="driver">org.postgresql.Driver</str>
<str name="url">${solr.cf.jdbc.url}</str>
<str name="user">${solr.cf.jdbc.user}</str>
<str name="password">${solr.cf.jdbc.password}</str>
</lst>
</lst>
</requestHandler>
我的架构文件:
<field name="entityId" type="uuid" required="true" />
<fieldType name="uuid" class="solr.UUIDField" indexed="true" />
使这项工作的唯一解决方法是向id添加一个空格,以便将其转换为如下字符串:
<field column="dummy_entityid" name="entityId" template="${entity.id} " />