I have following Spring MongoDB repository class. When I am trying to access this method I am getting following exception. Could you please let me know what's wrong with this one or how to populate Table from JSON? I am using Java 8, Spring 4 and Spring-mongo 1.9. None of the parameters is null. Is is something wrong with persisting/ converting Table interface?
@Repository
public interface OrganizationAttributeMetadataRepository extends MongoRepository<OrganizationAttributeMetaData, String> {
@Query(value="{ 'orgHierachyIdentifier' : ?0,'uniquecode': ?1}",fields="{'htmlAttributes':1}")
public Optional<OrganizationAttributeMetaData> findByOrgHierachyIdentifierAndUniquecode(String orgHierachyIdentifier,String uniquecode);
}
Part of the Document class
public class OrganizationAttributeMetaData extends CommonDomainAttributes implements Cloneable, Serializable {
/**
*
*/
private static final long serialVersionUID = 1L;
private String attributeName;
private int orgid;
private String uniquecode; //3 Character unique code to uniquely identify
Table<Integer, String, HTMLInputTag> htmlAttributes = null; //row,identifier and HTML
}
public abstract class CommonDomainAttributes {
@Id
protected String id;
protected String orgHierachyIdentifier;
@CreatedDate
protected Date createDate;
@LastModifiedDate
protected Date lastModifiedDate;
@CreatedBy
protected String createdBy;
@LastModifiedBy
protected String lastModifiedBy;
}
Exeption
%PARSER_ERROR[stack]web - 2016-12-31 13:17:06,867 [localhost-startStop-1] DEBUG o.s.d.m.r.q.StringBasedMongoQuery - Created query { "orgHierachyIdentifier" : "-999" , "uniquecode" : "ORG"} for null fields.
%PARSER_ERROR[stack]web - 2016-12-31 13:17:06,868 [localhost-startStop-1] DEBUG o.s.d.m.c.MongoTemplate - find using query: { "orgHierachyIdentifier" : "-999" , "uniquecode" : "ORG"} fields: null for class: class com.debopam.amsapp.model.OrganizationAttributeMetaData in collection: OrganizationAttributeMetaData
%PARSER_ERROR[stack]web - 2016-12-31 13:17:06,868 [localhost-startStop-1] DEBUG o.s.d.m.c.MongoDbUtils - Getting Mongo Database name=[amsapp]
%PARSER_ERROR[stack]web - 2016-12-31 13:17:06,890 [localhost-startStop-1] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Returning cached instance of singleton bean 'delegatingApplicationListener'
%PARSER_ERROR[stack]web - 2016-12-31 13:17:06,890 [localhost-startStop-1] DEBUG o.s.d.m.c.i.MongoPersistentEntityIndexCreator - Analyzing class interface com.google.common.base.Supplier for index information.
%PARSER_ERROR[stack]web - 2016-12-31 13:17:06,904 [localhost-startStop-1] DEBUG o.s.d.m.c.i.MongoPersistentEntityIndexCreator - Analyzing class interface com.google.common.collect.Table$Cell for index information.
%PARSER_ERROR[stack]web - 2016-12-31 13:17:06,906 [localhost-startStop-1] DEBUG o.s.d.m.c.i.MongoPersistentEntityIndexCreator - Analyzing class class com.google.common.collect.HashBasedTable for index information.
%PARSER_ERROR[stack]web - 2016-12-31 13:17:06,915 [localhost-startStop-1] DEBUG o.s.d.m.c.i.MongoPersistentEntityIndexCreator - Analyzing class class com.debopam.amsapp.model.HTMLAttribute for index information.
%PARSER_ERROR[stack]web - 2016-12-31 13:17:06,916 [localhost-startStop-1] DEBUG o.s.d.m.c.i.MongoPersistentEntityIndexCreator - Analyzing class class com.debopam.amsapp.model.HTMLInputTag for index information.
java.lang.ArrayIndexOutOfBoundsException: 1
at org.springframework.data.util.TypeDiscoverer.createInfo(TypeDiscoverer.java:121)
at org.springframework.data.util.ParentTypeAwareTypeInformation.createInfo(ParentTypeAwareTypeInformation.java:73)
at org.springframework.data.util.TypeDiscoverer.specialize(TypeDiscoverer.java:513)
at org.springframework.data.util.ParentTypeAwareTypeInformation.specialize(ParentTypeAwareTypeInformation.java:28)
at org.springframework.data.convert.DefaultTypeMapper.readType(DefaultTypeMapper.java:159)
at org.springframework.data.mongodb.core.convert.MappingMongoConverter.read(MappingMongoConverter.java:202)
at org.springframework.data.mongodb.core.convert.MappingMongoConverter.readValue(MappingMongoConverter.java:1197)
at org.springframework.data.mongodb.core.convert.MappingMongoConverter.access$200(MappingMongoConverter.java:79)
at org.springframework.data.mongodb.core.convert.MappingMongoConverter$MongoDbPropertyValueProvider.getPropertyValue(MappingMongoConverter.java:1145)
at org.springframework.data.mongodb.core.convert.MappingMongoConverter$MongoDbPropertyValueProvider.getPropertyValue(MappingMongoConverter.java:1108)
at org.springframework.data.mapping.model.PersistentEntityParameterValueProvider.getParameterValue(PersistentEntityParameterValueProvider.java:78)
at org.springframework.data.mapping.model.SpELExpressionParameterValueProvider.getParameterValue(SpELExpressionParameterValueProvider.java:63)
at org.springframework.data.convert.ReflectionEntityInstantiator.createInstance(ReflectionEntityInstantiator.java:71)
at org.springframework.data.convert.ClassGeneratingEntityInstantiator.createInstance(ClassGeneratingEntityInstantiator.java:83)
at org.springframework.data.mongodb.core.convert.MappingMongoConverter.read(MappingMongoConverter.java:252)
at org.springframework.data.mongodb.core.convert.MappingMongoConverter.read(MappingMongoConverter.java:232)
at org.springframework.data.mongodb.core.convert.MappingMongoConverter.readValue(MappingMongoConverter.java:1197)
at org.springframework.data.mongodb.core.convert.MappingMongoConverter.access$200(MappingMongoConverter.java:79)
at org.springframework.data.mongodb.core.convert.MappingMongoConverter$MongoDbPropertyValueProvider.getPropertyValue(MappingMongoConverter.java:1145)
at org.springframework.data.mongodb.core.convert.MappingMongoConverter.getValueInternal(MappingMongoConverter.java:871)
at org.springframework.data.mongodb.core.convert.MappingMongoConverter$1.doWithPersistentProperty(MappingMongoConverter.java:284)
at org.springframework.data.mongodb.core.convert.MappingMongoConverter$1.doWithPersistentProperty(MappingMongoConverter.java:272)
at org.springframework.data.mapping.model.BasicPersistentEntity.doWithProperties(BasicPersistentEntity.java:312)
at org.springframework.data.mongodb.core.convert.MappingMongoConverter.read(MappingMongoConverter.java:272)
at org.springframework.data.mongodb.core.convert.MappingMongoConverter.read(MappingMongoConverter.java:232)
at org.springframework.data.mongodb.core.convert.MappingMongoConverter.read(MappingMongoConverter.java:192)
at org.springframework.data.mongodb.core.convert.MappingMongoConverter.read(MappingMongoConverter.java:188)
at org.springframework.data.mongodb.core.convert.MappingMongoConverter.read(MappingMongoConverter.java:79)
at org.springframework.data.mongodb.core.MongoTemplate$ReadDbObjectCallback.doWith(MongoTemplate.java:2295)
at org.springframework.data.mongodb.core.MongoTemplate.executeFindMultiInternal(MongoTemplate.java:1949)
at org.springframework.data.mongodb.core.MongoTemplate.doFind(MongoTemplate.java:1767)
at org.springframework.data.mongodb.core.MongoTemplate.doFind(MongoTemplate.java:1750)
at org.springframework.data.mongodb.core.MongoTemplate.find(MongoTemplate.java:624)
at org.springframework.data.mongodb.core.MongoTemplate.findOne(MongoTemplate.java:589)
at org.springframework.data.mongodb.repository.query.MongoQueryExecution$SingleEntityExecution.execute(MongoQueryExecution.java:166)
at org.springframework.data.mongodb.repository.query.MongoQueryExecution$ResultProcessingExecution.execute(MongoQueryExecution.java:345)
at org.springframework.data.mongodb.repository.query.AbstractMongoQuery.execute(AbstractMongoQuery.java:91)
at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.doInvoke(RepositoryFactorySupport.java:482)
at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.invoke(RepositoryFactorySupport.java:460)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.data.projection.DefaultMethodInvokingMethodInterceptor.invoke(DefaultMethodInvokingMethodInterceptor.java:61)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:213)
at com.sun.proxy.$Proxy70.findByOrgHierachyIdentifierAndUniquecode(Unknown Source)
at com.debopam.amsapp.service.OrganizationAttributeMetaDataService.createOrganizationAttributeMetaData(OrganizationAttributeMetaDataService.java:54)
at com.debopam.amsapp.config.SetupDataLoader.onApplicationEvent(SetupDataLoader.java:78)
at com.debopam.amsapp.config.SetupDataLoader.onApplicationEvent(SetupDataLoader.java:1)
at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:166)
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:138)
at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:383)
at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:337)
at org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:882)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:545)
at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:444)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:326)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:107)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4725)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5189)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1404)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1394)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
I have written a custom converter to solve this problem. Here is the code sample