本文介绍了Hibernate Search无法使用@IdClass使用复合主键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在班级Intervento上配置了hibernate-search注释(4.1.1版本库).因此,我正在使用jpa,在我的情况下,我可以省略@DocumentId,但是我有一个复合主键...

...

我要....你能帮我吗?

错误:HSEARCH000058:HSEARCH000116:MassIndexer操作期间发生意外错误java.lang.ClassCastException:it.domain.InterventoPK无法转换为java.lang.Integer 在org.hibernate.type.descriptor.java.IntegerTypeDescriptor.unwrap(IntegerTypeDescriptor.java:36) 在org.hibernate.type.descriptor.sql.IntegerTypeDescriptor $ 1.doBind(IntegerTypeDescriptor.java:57) 在org.hibernate.type.descriptor.sql.BasicBinder.bind(BasicBinder.java:92) 在org.hibernate.type.AbstractStandardBasicType.nullSafeSet(AbstractStandardBasicType.java:305) 在org.hibernate.type.AbstractStandardBasicType.nullSafeSet(AbstractStandardBasicType.java:300) 在org.hibernate.loader.Loader.bindPositionalParameters(Loader.java:1891) 在org.hibernate.loader.Loader.bindParameterValues(Loader.java:1862) 在org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1737) 在org.hibernate.loader.Loader.doQuery(Loader.java:828) 在org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:289) 在org.hibernate.loader.Loader.doList(Loader.java:2447) 在org.hibernate.loader.Loader.doList(Loader.java:2433) 在org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2263) 在org.hibernate.loader.Loader.list(Loader.java:2258) 在org.hibernate.loader.criteria.CriteriaLoader.list(CriteriaLoader.java:122) 在org.hibernate.internal.SessionImpl.list(SessionImpl.java:1535) 在org.hibernate.internal.CriteriaImpl.list(CriteriaImpl.java:374) 在org.hibernate.search.batchindexing.impl.IdentifierConsumerEntityProducer.loadList(IdentifierConsumerEntityProducer.java:150) 在org.hibernate.search.batchindexing.impl.IdentifierConsumerEntityProducer.loadAllFromQueue(IdentifierConsumerEntityProducer.java:117) 在org.hibernate.search.batchindexing.impl.IdentifierConsumerEntityProducer.run(IdentifierConsumerEntityProducer.java:94) 在org.hibernate.search.batchindexing.impl.OptionallyWrapInJTATransaction.run(OptionallyWrapInJTATransaction.java:84) 在java.util.concurrent.ThreadPoolExecutor $ Worker.runTask(ThreadPoolExecutor.java:886) 在java.util.concurrent.ThreadPoolExecutor $ Worker.run(ThreadPoolExecutor.java:908) 在java.lang.Thread.run(Thread.java:619)

解决方案

休眠搜索不处理与 @IdClass 一起使用的复合ID类.一种解决方法是使用 @EmbeddedId 并将 idintervento linguaIdlingua 放入 InterventoPK 中.

似乎您在Hibernate Search论坛上也问了同样的问题- https://forum.hibernate.org/viewtopic.php?f=9&t=1024512

I've configured with hibernate-search annotation (4.1.1 version library) my class Intervento. So, I'm using jpa and in my case i can omit @DocumentId but I have a composite primary key...

@IdClass(it.domain.InterventoPK.class)
@Entity
@Indexed
@AnalyzerDef(name = "interventongram", tokenizer = @TokenizerDef(factory = StandardTokenizerFactory.class),
filters = {
     @TokenFilterDef(factory = LowerCaseFilterFactory.class),
     @TokenFilterDef(factory = StopFilterFactory.class, params = {
         @Parameter(name = "words", value = "lucene/dictionary/stopwords.txt"),
         @Parameter(name = "ignoreCase", value = "true"),
         @Parameter(name = "enablePositionIncrements", value = "true")
     }),
     @TokenFilterDef(factory = ItalianLightStemFilterFactory.class),
     @TokenFilterDef(factory = SynonymFilterFactory.class, params = {
         @Parameter(name = "synonyms", value = "lucene/dictionary/synonyms.txt"),
         @Parameter(name = "expand", value = "true")
     }),
     @TokenFilterDef(factory = SnowballPorterFilterFactory.class, params = {
            @Parameter(name = "language", value = "Italian")
     })
})



@Table(name = "intervento", catalog = "gestionale")
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(namespace = "Clinigo/it/domain", name = "Intervento")
@XmlRootElement(namespace = "Clinigo/it/domain")
public class Intervento implements Serializable {

    private static final long serialVersionUID = 1L;

    /**
     */

    @Column(name = "idintervento", nullable = false)
    @Basic(fetch = FetchType.EAGER)
    @Id
    @XmlElement
    Integer idintervento;
    /**
     */

    @Column(name = "lingua_idlingua", nullable = false)
    @Basic(fetch = FetchType.EAGER)
    @Id
    @XmlElement
    Integer linguaIdlingua;
    /**
     */
    @Temporal(TemporalType.TIMESTAMP)
    @Column(name = "version", nullable = false)
    @Basic(fetch = FetchType.EAGER)
    @XmlElement
    Calendar version;

...

I'm getting....can you help me?

ERROR: HSEARCH000058: HSEARCH000116: Unexpected error during MassIndexer operationjava.lang.ClassCastException: it.domain.InterventoPK cannot be cast to java.lang.Integer at org.hibernate.type.descriptor.java.IntegerTypeDescriptor.unwrap(IntegerTypeDescriptor.java:36) at org.hibernate.type.descriptor.sql.IntegerTypeDescriptor$1.doBind(IntegerTypeDescriptor.java:57) at org.hibernate.type.descriptor.sql.BasicBinder.bind(BasicBinder.java:92) at org.hibernate.type.AbstractStandardBasicType.nullSafeSet(AbstractStandardBasicType.java:305) at org.hibernate.type.AbstractStandardBasicType.nullSafeSet(AbstractStandardBasicType.java:300) at org.hibernate.loader.Loader.bindPositionalParameters(Loader.java:1891) at org.hibernate.loader.Loader.bindParameterValues(Loader.java:1862) at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1737) at org.hibernate.loader.Loader.doQuery(Loader.java:828) at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:289) at org.hibernate.loader.Loader.doList(Loader.java:2447) at org.hibernate.loader.Loader.doList(Loader.java:2433) at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2263) at org.hibernate.loader.Loader.list(Loader.java:2258) at org.hibernate.loader.criteria.CriteriaLoader.list(CriteriaLoader.java:122) at org.hibernate.internal.SessionImpl.list(SessionImpl.java:1535) at org.hibernate.internal.CriteriaImpl.list(CriteriaImpl.java:374) at org.hibernate.search.batchindexing.impl.IdentifierConsumerEntityProducer.loadList(IdentifierConsumerEntityProducer.java:150) at org.hibernate.search.batchindexing.impl.IdentifierConsumerEntityProducer.loadAllFromQueue(IdentifierConsumerEntityProducer.java:117) at org.hibernate.search.batchindexing.impl.IdentifierConsumerEntityProducer.run(IdentifierConsumerEntityProducer.java:94) at org.hibernate.search.batchindexing.impl.OptionallyWrapInJTATransaction.run(OptionallyWrapInJTATransaction.java:84) at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) at java.lang.Thread.run(Thread.java:619)

解决方案

Hibernate Search does not handle composite id classes used with @IdClass. A workaround would be to use @EmbeddedId and place idintervento and linguaIdlingua into InterventoPK.

Seems also that you asked the same question on the Hibernate Search forum - https://forum.hibernate.org/viewtopic.php?f=9&t=1024512

这篇关于Hibernate Search无法使用@IdClass使用复合主键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 03:38