我在Hibernate事务的提交阶段为新记录建立索引时遇到了IllegalArgumentException
。
我有以下配置:
@Indexed(index = "quotation")
@Entity
@Table(name = "quotation")
public class QuotationEntity {
@IndexedEmbedded
@OneToMany(mappedBy = "quotation", fetch = FetchType.EAGER, cascade = { CascadeType.PERSIST, CascadeType.MERGE }, orphanRemoval = true)
private Set<QuotationLineEntity> quotationLines = new HashSet<>();
}
@Entity
@Inheritance(strategy = InheritanceType.JOINED)
@Table(name = "quotation_line")
public abstract class QuotationLineEntity {
}
@Indexed(index = "quotation_article")
@Entity
@Table(name = "quotation_article")
public class QuotationArcticleEntity extends QuotationLineEntity {
@Field
@Column(name = "designation")
private String designation;
}
@Entity
@Table(name = "quotation_item")
public class QuotationItemEntity extends QuotationLineEntity {
}
让我们想象一下,我创建了以下对象:带有2个quotationLines的引用:
建立索引时,我得到以下堆栈:
Caused by: java.lang.IllegalStateException: Could not get property value
at org.hibernate.search.util.impl.ReflectionHelper.getMemberValue(ReflectionHelper.java:93)
at org.hibernate.search.engine.spi.DocumentBuilderIndexedEntity.buildDocumentFieldsForProperties(DocumentBuilderIndexedEntity.java:563)
at org.hibernate.search.engine.spi.DocumentBuilderIndexedEntity.buildDocumentFields(DocumentBuilderIndexedEntity.java:413)
at org.hibernate.search.engine.spi.DocumentBuilderIndexedEntity.buildDocumentFieldsForEmbeddedObjects(DocumentBuilderIndexedEntity.java:485)
at org.hibernate.search.engine.spi.DocumentBuilderIndexedEntity.buildDocumentFields(DocumentBuilderIndexedEntity.java:429)
at org.hibernate.search.engine.spi.DocumentBuilderIndexedEntity.getDocument(DocumentBuilderIndexedEntity.java:351)
at org.hibernate.search.engine.spi.DocumentBuilderIndexedEntity.createAddWork(DocumentBuilderIndexedEntity.java:253)
at org.hibernate.search.engine.spi.DocumentBuilderIndexedEntity.addWorkToQueue(DocumentBuilderIndexedEntity.java:195)
at org.hibernate.search.engine.impl.WorkPlan$PerEntityWork.enqueueLuceneWork(WorkPlan.java:521)
at org.hibernate.search.engine.impl.WorkPlan$PerClassWork.enqueueLuceneWork(WorkPlan.java:283)
at org.hibernate.search.engine.impl.WorkPlan.getPlannedLuceneWork(WorkPlan.java:155)
at org.hibernate.search.backend.impl.WorkQueue.prepareWorkPlan(WorkQueue.java:114)
at org.hibernate.search.backend.impl.BatchedQueueingProcessor.prepareWorks(BatchedQueueingProcessor.java:55)
at org.hibernate.search.backend.impl.PostTransactionWorkQueueSynchronization.beforeCompletion(PostTransactionWorkQueueSynchronization.java:64)
at org.hibernate.search.backend.impl.EventSourceTransactionContext$BeforeCommitSynchronizationDelegator.beforeCompletion(EventSourceTransactionContext.java:204)
at org.hibernate.resource.transaction.internal.SynchronizationRegistryStandardImpl.notifySynchronizationsBeforeTransactionCompletion(SynchronizationRegistryStandardImpl.java:60)
... 84 more
Caused by: java.lang.IllegalArgumentException: Invoking designation with wrong parameters
at org.hibernate.annotations.common.reflection.java.JavaXProperty.invoke(JavaXProperty.java:87)
at org.hibernate.annotations.common.reflection.java.JavaXProperty.invoke(JavaXProperty.java:99)
at org.hibernate.search.util.impl.ReflectionHelper.getMemberValue(ReflectionHelper.java:90)
... 99 more
Caused by: java.lang.IllegalArgumentException: Can not set java.lang.String field entity.QuotationArticleEntity.designation to entity.QuotationItemEntity
at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:167)
at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:171)
at sun.reflect.UnsafeFieldAccessorImpl.ensureObj(UnsafeFieldAccessorImpl.java:58)
at sun.reflect.UnsafeObjectFieldAccessorImpl.get(UnsafeObjectFieldAccessorImpl.java:36)
at java.lang.reflect.Field.get(Field.java:393)
at org.hibernate.annotations.common.reflection.java.JavaXProperty.invoke(JavaXProperty.java:80)
... 101 more
我看到的是Hibernate Search的{{1}}试图访问每个子类(通过DocumentBuilderIndexedEntity.buildDocumentFieldsForProperties()
)上每个收集的元数据的成员>所有子类,这就是为什么QuotationArticleEntity.designation无法应用于QuotationItemEntity的原因。
备注:
有什么办法可以解决这个问题,还是Hibernate seach问题?
亲切的问候
答案 0 :(得分:0)
尝试使用
@Inheritance(strategy = InheritanceType.JOINED)
以下是有用的链接:
Okey您可以尝试
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
如果要使用
@Inheritance(strategy = InheritanceType.JOINED)
尝试在您的抽象类中使用某些ID,并在每个子类中使用
@PrimaryKeyJoinColumn()