Setting targetElement param in @IndexedEmbedded on collection causes runtime exception
--------------------------------------------------------------------------------------
Key: HSEARCH-1111
URL:
https://hibernate.onjira.com/browse/HSEARCH-1111
Project: Hibernate Search
Issue Type: Bug
Components: mapping
Affects Versions: 3.4.2
Environment: Hibernate 3.6.10, mysql 5.1
Reporter: Elmer van Chastelet
Attachments: embeddedTestWithAdditionalTargetClassField.diff
When I have an @IndexedEmbedded field with the targetElement set to a subclass of the
embedded type (at least the case for a collection), indexing goes wrong.
After seeing this behavior in my own app, I extended
src/test/java/org/hibernate/search/test/embedded/AbstractProduct to have a pricingFeatures
field:
{code:java}
@ManyToMany(mappedBy="product", cascade=CascadeType.ALL) //just to make the
test easier, cascade doesn't really make any business sense
@IndexedEmbedded(targetElement=PricingFeature.class)
private Set<ProductFeature> pricingFeatures = new
HashSet<ProductFeature>();
{code}
Added PricingFeature class:
{code:java}
package org.hibernate.search.test.embedded;
import org.hibernate.search.annotations.Field;
import org.hibernate.search.annotations.Index;
public class PricingFeature extends ProductFeature {
@Field(index= Index.UN_TOKENIZED)
private String price;
public String getPrice() {
return price;
}
public void setPrice(String price) {
this.price = price;
}
}
{code}
The test itself {{org.hibernate.search.test.embedded.EmbeddedTest}} is untouched, and
{{testEmbeddedToManyInSuperslass}} fails with the following exception:
{code}
EmbeddedTest
org.hibernate.search.test.embedded.EmbeddedTest
testEmbeddedToManyInSuperslass(org.hibernate.search.test.embedded.EmbeddedTest)
org.hibernate.HibernateException: Error while indexing in Hibernate Search (before
transaction completion)
at
org.hibernate.search.backend.impl.EventSourceTransactionContext$DelegateToSynchronizationOnBeforeTx.doBeforeTransactionCompletion(EventSourceTransactionContext.java:175)
at
org.hibernate.engine.ActionQueue$BeforeTransactionCompletionProcessQueue.beforeTransactionCompletion(ActionQueue.java:554)
at org.hibernate.engine.ActionQueue.beforeTransactionCompletion(ActionQueue.java:216)
at org.hibernate.impl.SessionImpl.beforeTransactionCompletion(SessionImpl.java:571)
at org.hibernate.jdbc.JDBCContext.beforeTransactionCompletion(JDBCContext.java:250)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:138)
at
org.hibernate.search.test.embedded.EmbeddedTest.testEmbeddedToManyInSuperslass(EmbeddedTest.java:368)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:616)
at junit.framework.TestCase.runTest(TestCase.java:168)
at
org.hibernate.testing.junit.functional.annotations.HibernateTestCase.runTest(HibernateTestCase.java:97)
at
org.hibernate.testing.junit.functional.annotations.HibernateTestCase.runBare(HibernateTestCase.java:85)
at junit.framework.TestResult$1.protect(TestResult.java:110)
at junit.framework.TestResult.runProtected(TestResult.java:128)
at junit.framework.TestResult.run(TestResult.java:113)
at junit.framework.TestCase.run(TestCase.java:124)
at junit.framework.TestSuite.runTest(TestSuite.java:243)
at junit.framework.TestSuite.run(TestSuite.java:238)
at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:83)
at
org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: java.lang.IllegalStateException: Could not get property value
at org.hibernate.search.util.ReflectionHelper.getMemberValue(ReflectionHelper.java:94)
at
org.hibernate.search.engine.DocumentBuilderIndexedEntity.buildDocumentFields(DocumentBuilderIndexedEntity.java:477)
at
org.hibernate.search.engine.DocumentBuilderIndexedEntity.buildDocumentFields(DocumentBuilderIndexedEntity.java:526)
at
org.hibernate.search.engine.DocumentBuilderIndexedEntity.getDocument(DocumentBuilderIndexedEntity.java:443)
at
org.hibernate.search.engine.DocumentBuilderIndexedEntity.createAddWork(DocumentBuilderIndexedEntity.java:380)
at
org.hibernate.search.engine.DocumentBuilderIndexedEntity.addWorkToQueue(DocumentBuilderIndexedEntity.java:358)
at
org.hibernate.search.engine.WorkPlan$PerEntityWork.enqueueLuceneWork(WorkPlan.java:456)
at
org.hibernate.search.engine.WorkPlan$PerClassWork.enqueueLuceneWork(WorkPlan.java:257)
at org.hibernate.search.engine.WorkPlan.getPlannedLuceneWork(WorkPlan.java:150)
at org.hibernate.search.backend.WorkQueue.prepareWorkPlan(WorkQueue.java:134)
at
org.hibernate.search.backend.impl.BatchedQueueingProcessor.prepareWorks(BatchedQueueingProcessor.java:124)
at
org.hibernate.search.backend.impl.PostTransactionWorkQueueSynchronization.beforeCompletion(PostTransactionWorkQueueSynchronization.java:89)
at
org.hibernate.search.backend.impl.EventSourceTransactionContext$DelegateToSynchronizationOnBeforeTx.doBeforeTransactionCompletion(EventSourceTransactionContext.java:172)
... 26 more
Caused by: java.lang.IllegalArgumentException: Invoking price with wrong parameters
at
org.hibernate.annotations.common.reflection.java.JavaXProperty.invoke(JavaXProperty.java:84)
at org.hibernate.search.util.ReflectionHelper.getMemberValue(ReflectionHelper.java:91)
... 38 more
Caused by: java.lang.IllegalArgumentException: Can not set java.lang.String field
org.hibernate.search.test.embedded.PricingFeature.price to
org.hibernate.search.test.embedded.ProductFeature
at
sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:164)
at
sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:168)
at sun.reflect.UnsafeFieldAccessorImpl.ensureObj(UnsafeFieldAccessorImpl.java:55)
at sun.reflect.UnsafeObjectFieldAccessorImpl.get(UnsafeObjectFieldAccessorImpl.java:36)
at java.lang.reflect.Field.get(Field.java:376)
at
org.hibernate.annotations.common.reflection.java.JavaXProperty.invoke(JavaXProperty.java:77)
... 39 more
{code}
This is probably also applicable for HSearch 4.1.0, but untested.
--
This message is automatically generated by JIRA.
For more information on JIRA, see:
http://www.atlassian.com/software/jira