javahibernatehibernate-mappinghibernate-searchhibernate-ogm

Hibernate OGM map a Map<String, Object> element collection


I 'm stuck in a situation where my Entity has a field of type Map<String, Object>. Trying to index data using a massIndexer I fell in this Exception that is mentioning the word bug. The way I use the mapping is presented below:

@ElementCollection(fetch = FetchType.EAGER)
private Map<String, Object> params;

When I use Map<String, String> it works fine. Is there a specific reason that this is not allowed or is actually a bug?

Exception in thread "main" javax.persistence.PersistenceException: [PersistenceUnit: ogm-persistence] Unable to build Hibernate SessionFactory
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.persistenceException(EntityManagerFactoryBuilderImpl.java:970)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:895)
at org.hibernate.jpa.HibernatePersistenceProvider.createEntityManagerFactory(HibernatePersistenceProvider.java:58)
at org.hibernate.ogm.jpa.HibernateOgmPersistence.createEntityManagerFactory(HibernateOgmPersistence.java:57)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:55)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:39)
at com.application.massindexerapplication.main.MassIndexerApplication.main(MassIndexerApplication.java:32)

Caused by: org.hibernate.MappingException: bug in initComponentPropertyPaths
at org.hibernate.persister.entity.AbstractPropertyMapping.initComponentPropertyPaths(AbstractPropertyMapping.java:442)
at org.hibernate.persister.collection.CompositeElementPropertyMapping.<init>(CompositeElementPropertyMapping.java:32)
at org.hibernate.persister.collection.AbstractCollectionPersister.<init>(AbstractCollectionPersister.java:525)
at org.hibernate.ogm.persister.impl.OgmCollectionPersister.<init>(OgmCollectionPersister.java:115)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at org.hibernate.persister.internal.PersisterFactoryImpl.createCollectionPersister(PersisterFactoryImpl.java:152)
at org.hibernate.persister.internal.PersisterFactoryImpl.createCollectionPersister(PersisterFactoryImpl.java:140)
at org.hibernate.metamodel.internal.MetamodelImpl.initialize(MetamodelImpl.java:171)
at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:300)
at org.hibernate.ogm.boot.impl.OgmSessionFactoryBuilderImpl.build(OgmSessionFactoryBuilderImpl.java:55)
at org.hibernate.ogm.boot.impl.OgmSessionFactoryBuilderImpl.build(OgmSessionFactoryBuilderImpl.java:23)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:892)
... 5 more

Caused by: java.lang.ArrayIndexOutOfBoundsException
at java.lang.System.arraycopy(Native Method)
at org.hibernate.internal.util.collections.ArrayHelper.slice(ArrayHelper.java:121)
at org.hibernate.persister.entity.AbstractPropertyMapping.initComponentPropertyPaths(AbstractPropertyMapping.java:425)
... 19 more

Hibernate OGM 5.3, Hibernate Search 5.9, ElasticSearch 5.5


Solution

  • @ElementCollection can only be used on a collection of instances of a basic type or embeddable class.

    String is a primitive type and therefore the mapping works. Object is not a primitive type nor an embeddable and therefore you have an error (not a clear one though).