From 84b83f03bb95090ace22c9a4031625f8b9e7df00 Mon Sep 17 00:00:00 2001 From: Martin Braun Date: Mon, 27 Jul 2015 23:53:22 +0200 Subject: [PATCH] #91 EclipseLink update integration works for now, cleanups are needed though --- .../db/events/index/impl/IndexUpdater.java | 28 ++-- .../EclipseLinkGlassFishIntegrationTest.java | 2 + .../OpenJPATomEEIntegrationTest.java | 2 + .../HibernateWildFlyIntegrationTest.java | 2 + .../hibernate/search/genericjpa/Setup.java | 2 +- ...eLinkSynchronizedUpdateSourceProvider.java | 14 +- .../impl/EclipseLinkUpdateSource.java | 121 +++++++++++++++++- .../impl/JPASearchFactoryAdapter.java | 4 +- .../SynchronizedUpdateSourceProvider.java | 5 + ...seLinkAutomaticUpdatesIntegrationTest.java | 12 +- .../metadata/impl/MetadataRehasher.java | 1 + .../metadata/impl/RehashedTypeMetadata.java | 10 ++ 12 files changed, 173 insertions(+), 30 deletions(-) diff --git a/db/src/main/java/org/hibernate/search/genericjpa/db/events/index/impl/IndexUpdater.java b/db/src/main/java/org/hibernate/search/genericjpa/db/events/index/impl/IndexUpdater.java index 660730a..9e6c2dd 100644 --- a/db/src/main/java/org/hibernate/search/genericjpa/db/events/index/impl/IndexUpdater.java +++ b/db/src/main/java/org/hibernate/search/genericjpa/db/events/index/impl/IndexUpdater.java @@ -239,20 +239,6 @@ public void delete(Class entityClass, List> inIndexOf, Object id, Tr else { idValueForDeletion = id; } - HSQuery hsQuery = this.searchIntegrator - .createHSQuery() - .targetedEntities( Collections.singletonList( indexClass ) ) - .luceneQuery( - this.searchIntegrator.buildQueryBuilder() - .forEntity( indexClass ) - .get() - .keyword() - .onField( field ) - .matching( idValueForDeletion ) - .createQuery() - ); - int count = hsQuery.queryResultSize(); - int processed = 0; if ( indexClass.equals( entityClass ) ) { this.searchIntegrator.getWorker().performWork( new Work( @@ -263,6 +249,20 @@ public void delete(Class entityClass, List> inIndexOf, Object id, Tr ); } else { + HSQuery hsQuery = this.searchIntegrator + .createHSQuery() + .targetedEntities( Collections.singletonList( indexClass ) ) + .luceneQuery( + this.searchIntegrator.buildQueryBuilder() + .forEntity( indexClass ) + .get() + .keyword() + .onField( field ) + .matching( idValueForDeletion ) + .createQuery() + ); + int count = hsQuery.queryResultSize(); + int processed = 0; // this was just contained somewhere // so we have to update the containing entity while ( processed < count ) { diff --git a/integrationtest/glassfish/src/test/java/org/hibernate/search/genericjpa/test/integration/EclipseLinkGlassFishIntegrationTest.java b/integrationtest/glassfish/src/test/java/org/hibernate/search/genericjpa/test/integration/EclipseLinkGlassFishIntegrationTest.java index d8ef701..8ce9ce9 100644 --- a/integrationtest/glassfish/src/test/java/org/hibernate/search/genericjpa/test/integration/EclipseLinkGlassFishIntegrationTest.java +++ b/integrationtest/glassfish/src/test/java/org/hibernate/search/genericjpa/test/integration/EclipseLinkGlassFishIntegrationTest.java @@ -228,6 +228,7 @@ public void testManualIndexing() throws Exception { FullTextEntityManager fem = this.searchFactory.getFullTextEntityManager( this.em ); fem.beginSearchTransaction(); Game newGame = new Game( "Legend of Zelda" ); + newGame.setId( -10L ); fem.index( newGame ); fem.commitSearchTransaction(); Sleep.sleep( @@ -254,6 +255,7 @@ public void testRollback() throws Exception { fem.beginSearchTransaction(); Game newGame = new Game( "Pong" ); fem.index( newGame ); + newGame.setId( -10L ); fem.rollbackSearchTransaction(); Sleep.sleep( MAX_SLEEP_TIME, () -> { diff --git a/integrationtest/tomee/src/test/java/org/hibernate/search/genericjpa/test/integration/OpenJPATomEEIntegrationTest.java b/integrationtest/tomee/src/test/java/org/hibernate/search/genericjpa/test/integration/OpenJPATomEEIntegrationTest.java index b646a24..e2532d1 100644 --- a/integrationtest/tomee/src/test/java/org/hibernate/search/genericjpa/test/integration/OpenJPATomEEIntegrationTest.java +++ b/integrationtest/tomee/src/test/java/org/hibernate/search/genericjpa/test/integration/OpenJPATomEEIntegrationTest.java @@ -235,6 +235,7 @@ public void testManualIndexing() throws Exception { FullTextEntityManager fem = this.searchFactory.getFullTextEntityManager( this.em ); fem.beginSearchTransaction(); Game newGame = new Game( "Legend of Zelda" ); + newGame.setId( -10L ); fem.index( newGame ); fem.commitSearchTransaction(); Sleep.sleep( @@ -260,6 +261,7 @@ public void testRollback() throws Exception { FullTextEntityManager fem = this.searchFactory.getFullTextEntityManager( this.em ); fem.beginSearchTransaction(); Game newGame = new Game( "Pong" ); + newGame.setId( -10L ); fem.index( newGame ); fem.rollbackSearchTransaction(); Sleep.sleep( diff --git a/integrationtest/wildfly/src/test/java/org/hibernate/search/genericjpa/test/integration/HibernateWildFlyIntegrationTest.java b/integrationtest/wildfly/src/test/java/org/hibernate/search/genericjpa/test/integration/HibernateWildFlyIntegrationTest.java index 2eccd01..e8e7d5f 100644 --- a/integrationtest/wildfly/src/test/java/org/hibernate/search/genericjpa/test/integration/HibernateWildFlyIntegrationTest.java +++ b/integrationtest/wildfly/src/test/java/org/hibernate/search/genericjpa/test/integration/HibernateWildFlyIntegrationTest.java @@ -234,6 +234,7 @@ public void testManualIndexing() throws Exception { FullTextEntityManager fem = this.searchFactory.getFullTextEntityManager( this.em ); fem.beginSearchTransaction(); Game newGame = new Game( "Legend of Zelda" ); + newGame.setId( -10L ); fem.index( newGame ); fem.commitSearchTransaction(); Sleep.sleep( @@ -260,6 +261,7 @@ public void testRollback() throws Exception { fem.beginSearchTransaction(); Game newGame = new Game( "Pong" ); fem.index( newGame ); + newGame.setId( -10L ); fem.rollbackSearchTransaction(); Sleep.sleep( MAX_SLEEP_TIME, () -> { diff --git a/jpa/src/main/java/org/hibernate/search/genericjpa/Setup.java b/jpa/src/main/java/org/hibernate/search/genericjpa/Setup.java index 957e5e0..de50006 100644 --- a/jpa/src/main/java/org/hibernate/search/genericjpa/Setup.java +++ b/jpa/src/main/java/org/hibernate/search/genericjpa/Setup.java @@ -145,7 +145,7 @@ public static JPASearchFactoryController createSearchFactoryController(EntityMan SEARCH_FACTORY_TYPE_DEFAULT_VALUE ); //what AsyncUpdateSource to be used - SynchronizedUpdateSourceProvider synchronizedUpdateSourceProvider = (a, b, c, d, e) -> null; + SynchronizedUpdateSourceProvider synchronizedUpdateSourceProvider = (a, b, c, d, e, f, g) -> null; AsyncUpdateSourceProvider asyncUpdateSourceProvider = (a, b, c, d, e, f) -> null; if ( "sql".equals( type ) ) { if ( emf == null ) { diff --git a/jpa/src/main/java/org/hibernate/search/genericjpa/db/events/eclipselink/impl/EclipseLinkSynchronizedUpdateSourceProvider.java b/jpa/src/main/java/org/hibernate/search/genericjpa/db/events/eclipselink/impl/EclipseLinkSynchronizedUpdateSourceProvider.java index 7d1b3b6..af5e870 100644 --- a/jpa/src/main/java/org/hibernate/search/genericjpa/db/events/eclipselink/impl/EclipseLinkSynchronizedUpdateSourceProvider.java +++ b/jpa/src/main/java/org/hibernate/search/genericjpa/db/events/eclipselink/impl/EclipseLinkSynchronizedUpdateSourceProvider.java @@ -8,6 +8,8 @@ import javax.persistence.EntityManagerFactory; import javax.transaction.TransactionManager; +import java.util.List; +import java.util.Map; import java.util.Properties; import java.util.Set; @@ -17,6 +19,7 @@ import org.hibernate.search.genericjpa.JPASearchFactoryController; import org.hibernate.search.genericjpa.events.impl.SynchronizedUpdateSource; import org.hibernate.search.genericjpa.impl.SynchronizedUpdateSourceProvider; +import org.hibernate.search.genericjpa.metadata.impl.RehashedTypeMetadata; /** * Created by Martin on 27.07.2015. @@ -26,6 +29,8 @@ public class EclipseLinkSynchronizedUpdateSourceProvider implements Synchronized @Override public SynchronizedUpdateSource getUpdateSource( JPASearchFactoryController searchFactoryController, + Map, RehashedTypeMetadata> rehashedTypeMetadataPerIndexRoot, + Map, List>> containedInIndexOf, Properties properties, EntityManagerFactory emf, TransactionManager transactionManager, @@ -36,10 +41,12 @@ public SynchronizedUpdateSource getUpdateSource( EclipseLinkUpdateSource eclipseLinkUpdateSource = new EclipseLinkUpdateSource( searchFactoryController, - indexRelevantEntities + indexRelevantEntities, + rehashedTypeMetadataPerIndexRoot, + containedInIndexOf ); for ( Class entity : indexRelevantEntities ) { - if(session.getDescriptor( entity ) == null) { + if ( session.getDescriptor( entity ) == null ) { //no JPA entity continue; } @@ -49,7 +56,8 @@ public SynchronizedUpdateSource getUpdateSource( } session.getEventManager().addListener( eclipseLinkUpdateSource.sessionEventAspect ); return eclipseLinkUpdateSource; - } finally { + } + finally { entityManager.close(); } } diff --git a/jpa/src/main/java/org/hibernate/search/genericjpa/db/events/eclipselink/impl/EclipseLinkUpdateSource.java b/jpa/src/main/java/org/hibernate/search/genericjpa/db/events/eclipselink/impl/EclipseLinkUpdateSource.java index 146e9c3..e8643c4 100644 --- a/jpa/src/main/java/org/hibernate/search/genericjpa/db/events/eclipselink/impl/EclipseLinkUpdateSource.java +++ b/jpa/src/main/java/org/hibernate/search/genericjpa/db/events/eclipselink/impl/EclipseLinkUpdateSource.java @@ -6,24 +6,43 @@ */ package org.hibernate.search.genericjpa.db.events.eclipselink.impl; +import javax.persistence.EntityManagerFactory; import java.io.Serializable; +import java.util.Collections; import java.util.List; +import java.util.Map; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; import java.util.logging.Logger; import org.eclipse.persistence.descriptors.DescriptorEvent; import org.eclipse.persistence.descriptors.DescriptorEventAdapter; +import org.eclipse.persistence.expressions.Expression; +import org.eclipse.persistence.internal.sessions.UnitOfWorkImpl; +import org.eclipse.persistence.queries.ObjectLevelReadQuery; +import org.eclipse.persistence.queries.ReadObjectQuery; import org.eclipse.persistence.sessions.Session; import org.eclipse.persistence.sessions.SessionEvent; import org.eclipse.persistence.sessions.SessionEventAdapter; import org.eclipse.persistence.sessions.UnitOfWork; +import org.hibernate.annotations.common.reflection.XProperty; +import org.hibernate.search.backend.spi.SingularTermDeletionQuery; +import org.hibernate.search.backend.spi.Work; +import org.hibernate.search.backend.spi.WorkType; +import org.hibernate.search.bridge.FieldBridge; +import org.hibernate.search.bridge.StringBridge; +import org.hibernate.search.engine.ProjectionConstants; +import org.hibernate.search.engine.metadata.impl.DocumentFieldMetadata; import org.hibernate.search.genericjpa.JPASearchFactoryController; import org.hibernate.search.genericjpa.events.impl.SynchronizedUpdateSource; import org.hibernate.search.genericjpa.factory.Transaction; import org.hibernate.search.genericjpa.factory.impl.SubClassSupportInstanceInitializer; +import org.hibernate.search.genericjpa.metadata.impl.RehashedTypeMetadata; import org.hibernate.search.jpa.FullTextEntityManager; +import org.hibernate.search.jpa.FullTextQuery; +import org.hibernate.search.query.engine.spi.EntityInfo; +import org.hibernate.search.query.engine.spi.HSQuery; import org.hibernate.search.spi.InstanceInitializer; /** @@ -31,12 +50,18 @@ */ public class EclipseLinkUpdateSource implements SynchronizedUpdateSource { + //TODO: use an abstraction of IndexUpdater here. we don't want the logic to be duplicated + + private static final int HSQUERY_BATCH = 50; + private static Logger LOGGER = Logger.getLogger( EclipseLinkUpdateSource.class.getName() ); private static final InstanceInitializer INSTANCE_INITIALIZER = SubClassSupportInstanceInitializer.INSTANCE; private final JPASearchFactoryController searchFactoryController; private final Set> indexRelevantEntities; + private final Map, RehashedTypeMetadata> rehashedTypeMetadataPerIndexRoot; + private final Map, List>> containedInIndexOf; final DescriptorEventAspect descriptorEventAspect; final SessionEventAspect sessionEventAspect; @@ -45,22 +70,27 @@ public class EclipseLinkUpdateSource implements SynchronizedUpdateSource { public EclipseLinkUpdateSource( JPASearchFactoryController searchFactoryController, - Set> indexRelevantEntities) { + Set> indexRelevantEntities, + Map, RehashedTypeMetadata> rehashedTypeMetadataPerIndexRoot, + Map, List>> containedInIndexOf) { this.searchFactoryController = searchFactoryController; this.indexRelevantEntities = indexRelevantEntities; this.descriptorEventAspect = new DescriptorEventAspect(); this.sessionEventAspect = new SessionEventAspect(); + this.rehashedTypeMetadataPerIndexRoot = rehashedTypeMetadataPerIndexRoot; + this.containedInIndexOf = containedInIndexOf; } private class DescriptorEventAspect extends DescriptorEventAdapter { + @Override public void postInsert(DescriptorEvent event) { Object entity = event.getObject(); Class entityClass = INSTANCE_INITIALIZER.getClass( entity ); if ( EclipseLinkUpdateSource.this.indexRelevantEntities.contains( entityClass ) ) { LOGGER.fine( "Insert Event for " + entity ); Session session = event.getSession(); - if(session.isUnitOfWork()) { + if ( session.isUnitOfWork() ) { session = ((UnitOfWork) session).getParent(); } FullTextEntityManager fem = EclipseLinkUpdateSource.this.fullTextEntityManagers.get( session ); @@ -68,13 +98,14 @@ public void postInsert(DescriptorEvent event) { } } + @Override public void postUpdate(DescriptorEvent event) { Object entity = event.getObject(); Class entityClass = INSTANCE_INITIALIZER.getClass( entity ); if ( EclipseLinkUpdateSource.this.indexRelevantEntities.contains( entityClass ) ) { LOGGER.fine( "Update Event for " + entity ); Session session = event.getSession(); - if(session.isUnitOfWork()) { + if ( session.isUnitOfWork() ) { session = ((UnitOfWork) session).getParent(); } FullTextEntityManager fem = EclipseLinkUpdateSource.this.fullTextEntityManagers.get( session ); @@ -82,6 +113,7 @@ public void postUpdate(DescriptorEvent event) { } } + @Override public void postDelete(DescriptorEvent event) { //we have to do stuff similar to IndexUpdater here. //we have to check in which index this object was found and @@ -94,12 +126,86 @@ public void postDelete(DescriptorEvent event) { if ( EclipseLinkUpdateSource.this.indexRelevantEntities.contains( entityClass ) ) { LOGGER.fine( "Delete Event for " + entity ); Session session = event.getSession(); - if(session.isUnitOfWork()) { + if ( session.isUnitOfWork() ) { session = ((UnitOfWork) session).getParent(); } FullTextEntityManager fem = EclipseLinkUpdateSource.this.fullTextEntityManagers.get( session ); - Object id = session.getId( entity ); - fem.purge( entityClass, (Serializable) id ); + List> inIndexOf = EclipseLinkUpdateSource.this.containedInIndexOf.get( entityClass ); + for ( Class indexClass : inIndexOf ) { + RehashedTypeMetadata metadata = EclipseLinkUpdateSource.this.rehashedTypeMetadataPerIndexRoot.get( + indexClass + ); + + XProperty idProperty = metadata.getIdPropertyAccessorForType().get( entityClass ); + Object id = idProperty.invoke( entity ); + + List fields = metadata.getIdFieldNamesForType().get( entityClass ); + for ( String field : fields ) { + DocumentFieldMetadata metaDataForIdField = metadata.getDocumentFieldMetadataForIdFieldName() + .get( + field + ); + + SingularTermDeletionQuery.Type idType = metadata.getSingularTermDeletionQueryTypeForIdFieldName() + .get( entityClass ); + Object idValueForDeletion; + if ( idType == SingularTermDeletionQuery.Type.STRING ) { + FieldBridge fb = metaDataForIdField.getFieldBridge(); + if ( !(fb instanceof StringBridge) ) { + throw new IllegalArgumentException( "no TwoWayStringBridge found for field: " + field ); + } + idValueForDeletion = ((StringBridge) fb).objectToString( id ); + } + else { + idValueForDeletion = id; + } + + if ( indexClass.equals( entityClass ) ) { + fem.purge( entityClass, (Serializable) id ); + } + else { + FullTextQuery fullTextQuery = fem.createFullTextQuery( + fem.getSearchFactory() + .buildQueryBuilder() + .forEntity( indexClass ) + .get() + .keyword() + .onField( field ) + .matching( idValueForDeletion ) + .createQuery(), indexClass + ); + + fullTextQuery.setMaxResults( HSQUERY_BATCH ); + fullTextQuery.setProjection( ProjectionConstants.ID ); + + int count = fullTextQuery.getResultSize(); + int processed = 0; + // this was just contained somewhere + // so we have to update the containing entity + while ( processed < count ) { + fullTextQuery.setFirstResult( processed ); + for ( Object[] projection : (List) fullTextQuery.getResultList() ) { + Serializable originalId = (Serializable) projection[0]; + ReadObjectQuery nativeQuery = new ReadObjectQuery(); + nativeQuery.setReferenceClass( indexClass ); + nativeQuery.setSelectionId( originalId ); + nativeQuery.setCacheUsage( ObjectLevelReadQuery.DoNotCheckCache ); + Object original = session.executeQuery( nativeQuery ); + if ( original != null ) { + fem.index( original ); + } + else { + // original is not available in the + // database, but it will be deleted by its + // own delete event + // TODO: log this? + } + } + processed += HSQUERY_BATCH; + } + } + } + } } } @@ -107,6 +213,7 @@ public void postDelete(DescriptorEvent event) { private class SessionEventAspect extends SessionEventAdapter { + @Override public void postBeginTransaction(SessionEvent event) { Session session = event.getSession(); FullTextEntityManager fem = EclipseLinkUpdateSource.this.fullTextEntityManagers.get( session ); @@ -120,6 +227,7 @@ public void postBeginTransaction(SessionEvent event) { } } + @Override public void postCommitTransaction(SessionEvent event) { Session session = event.getSession(); FullTextEntityManager fem = EclipseLinkUpdateSource.this.fullTextEntityManagers.get( session ); @@ -134,6 +242,7 @@ public void postCommitTransaction(SessionEvent event) { } } + @Override public void postRollbackTransaction(SessionEvent event) { Session session = event.getSession(); FullTextEntityManager fem = EclipseLinkUpdateSource.this.fullTextEntityManagers.get( session ); diff --git a/jpa/src/main/java/org/hibernate/search/genericjpa/impl/JPASearchFactoryAdapter.java b/jpa/src/main/java/org/hibernate/search/genericjpa/impl/JPASearchFactoryAdapter.java index 9a7ecf1..7c820b6 100644 --- a/jpa/src/main/java/org/hibernate/search/genericjpa/impl/JPASearchFactoryAdapter.java +++ b/jpa/src/main/java/org/hibernate/search/genericjpa/impl/JPASearchFactoryAdapter.java @@ -152,6 +152,7 @@ public final void init() { ) ); this.idProperties = MetadataUtil.calculateIdProperties( rehashedTypeMetadatas ); + this.containedInIndexOf = MetadataUtil.calculateInIndexOf( rehashedTypeMetadatas ); SearchIntegratorBuilder builder = new SearchIntegratorBuilder(); // we have to build an integrator here (but we don't need it afterwards) @@ -177,7 +178,6 @@ public final void init() { if ( this.emf == null ) { throw new AssertionFailure( "emf may not be null when using an AsyncUpdateSource" ); } - this.containedInIndexOf = MetadataUtil.calculateInIndexOf( rehashedTypeMetadatas ); JPAReusableEntityProvider entityProvider = new JPAReusableEntityProvider( this.emf, @@ -198,6 +198,8 @@ public final void init() { } this.synchronizedUpdateSource = this.synchronizedUpdateSourceProvider.getUpdateSource( this, + this.rehashedTypeMetadataForIndexRoot, + this.containedInIndexOf, this.properties, this.emf, this.transactionManager, diff --git a/jpa/src/main/java/org/hibernate/search/genericjpa/impl/SynchronizedUpdateSourceProvider.java b/jpa/src/main/java/org/hibernate/search/genericjpa/impl/SynchronizedUpdateSourceProvider.java index 92a7164..88ae5ef 100644 --- a/jpa/src/main/java/org/hibernate/search/genericjpa/impl/SynchronizedUpdateSourceProvider.java +++ b/jpa/src/main/java/org/hibernate/search/genericjpa/impl/SynchronizedUpdateSourceProvider.java @@ -8,12 +8,15 @@ import javax.persistence.EntityManagerFactory; import javax.transaction.TransactionManager; +import java.util.List; +import java.util.Map; import java.util.Properties; import java.util.Set; import org.hibernate.search.genericjpa.JPASearchFactoryController; import org.hibernate.search.genericjpa.db.events.index.impl.IndexUpdater; import org.hibernate.search.genericjpa.events.impl.SynchronizedUpdateSource; +import org.hibernate.search.genericjpa.metadata.impl.RehashedTypeMetadata; /** * Created by Martin on 27.07.2015. @@ -22,6 +25,8 @@ public interface SynchronizedUpdateSourceProvider { SynchronizedUpdateSource getUpdateSource( JPASearchFactoryController searchFactoryController, + Map, RehashedTypeMetadata> rehashedTypeMetadataPerIndexRoot, + Map, List>> containedInIndexOf, Properties properties, EntityManagerFactory emf, TransactionManager transactionManager, diff --git a/jpa/src/test/java/org/hibernate/search/genericjpa/test/jpa/mysql/MySQLNativeEclipseLinkAutomaticUpdatesIntegrationTest.java b/jpa/src/test/java/org/hibernate/search/genericjpa/test/jpa/mysql/MySQLNativeEclipseLinkAutomaticUpdatesIntegrationTest.java index 04d44f4..cc42a34 100644 --- a/jpa/src/test/java/org/hibernate/search/genericjpa/test/jpa/mysql/MySQLNativeEclipseLinkAutomaticUpdatesIntegrationTest.java +++ b/jpa/src/test/java/org/hibernate/search/genericjpa/test/jpa/mysql/MySQLNativeEclipseLinkAutomaticUpdatesIntegrationTest.java @@ -36,6 +36,8 @@ public void setup() { this.setup( "eclipselink", "EclipseLink_MySQL", MySQLTriggerSQLStringSource.class ); } + //TODO: test this for object hierarchies + @Test public void testNativeEvents() { if ( "sql".equals( this.searchFactoryType ) ) { @@ -135,11 +137,11 @@ MultipleColumnsIdEntity.class, new ID( this.em.remove( ent ); this.em.getTransaction().commit(); - //assertEquals( - // 0, searchFactory.getFullTextEntityManager( this.em ) - // .createFullTextQuery( new MatchAllDocsQuery(), MultipleColumnsIdEntity.class ) - // .getResultSize() - //); + assertEquals( + 0, searchFactory.getFullTextEntityManager( this.em ) + .createFullTextQuery( new MatchAllDocsQuery(), MultipleColumnsIdEntity.class ) + .getResultSize() + ); } } finally { diff --git a/standalone/src/main/java/org/hibernate/search/genericjpa/metadata/impl/MetadataRehasher.java b/standalone/src/main/java/org/hibernate/search/genericjpa/metadata/impl/MetadataRehasher.java index ac3741b..2ea6e15 100644 --- a/standalone/src/main/java/org/hibernate/search/genericjpa/metadata/impl/MetadataRehasher.java +++ b/standalone/src/main/java/org/hibernate/search/genericjpa/metadata/impl/MetadataRehasher.java @@ -81,6 +81,7 @@ private boolean handlePropertyMetadata( if ( rehashed.documentFieldMetadataForIdFieldName.containsKey( documentFieldMetadata.getName() ) ) { throw new AssertionFailure( "field handled twice!" ); } + rehashed.idPropertyAccessorForType.put( type, propertyMetadata.getPropertyAccessor() ); rehashed.documentFieldMetadataForIdFieldName.put( documentFieldMetadata.getName(), documentFieldMetadata diff --git a/standalone/src/main/java/org/hibernate/search/genericjpa/metadata/impl/RehashedTypeMetadata.java b/standalone/src/main/java/org/hibernate/search/genericjpa/metadata/impl/RehashedTypeMetadata.java index 1fe2689..50dbef4 100644 --- a/standalone/src/main/java/org/hibernate/search/genericjpa/metadata/impl/RehashedTypeMetadata.java +++ b/standalone/src/main/java/org/hibernate/search/genericjpa/metadata/impl/RehashedTypeMetadata.java @@ -10,6 +10,7 @@ import java.util.List; import java.util.Map; +import org.hibernate.annotations.common.reflection.XProperty; import org.hibernate.search.backend.spi.SingularTermDeletionQuery; import org.hibernate.search.engine.metadata.impl.DocumentFieldMetadata; import org.hibernate.search.engine.metadata.impl.TypeMetadata; @@ -37,6 +38,8 @@ public final class RehashedTypeMetadata { */ Map, String> idPropertyNameForType = new HashMap<>(); + Map, XProperty> idPropertyAccessorForType = new HashMap<>(); + /** * this contains the DocumentFieldMetadata for each id-fieldname. This provides info about how each id is stored in * the index @@ -115,4 +118,11 @@ public void setSingularTermDeletionQueryTypeForIdFieldName(Map, XProperty> getIdPropertyAccessorForType() { + return idPropertyAccessorForType; + } + + public void setIdPropertyAccessorForType(Map, XProperty> idPropertyAccessorForType) { + this.idPropertyAccessorForType = idPropertyAccessorForType; + } }