Hibernate OGM映射Map <string,object =“”>元素集合

时间:2018-04-25 14:38:27

标签: java hibernate hibernate-mapping hibernate-search hibernate-ogm

我遇到的情况是我的实体有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 Search 5.9,ElasticSearch 5.5

1 个答案:

答案 0 :(得分:0)

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

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