Hibernate OGM映射一个Map<String, Object>元素集合

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

我被困在我的实体有一个 Map<String, Object> 类型的字段的情况下。尝试使用 massIndexer 索引数据时,我遇到了这个提到 bug 这个词的异常。我使用映射的方式如下:

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

当我使用 Map<String, String> 时它工作正常。是否有特定原因不允许这样做或实际上是错误?

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 搜索 5.9、ElasticSearch 5.5

@ElementCollection 只能用于基本类型或可嵌入实例的集合 class。

String 是原始类型,因此映射有效。 Object 不是原始类型,也不是可嵌入类型,因此您有一个错误(虽然不是很清楚)。