Hi,
As it seem to me, whenever i load objects from my database with CRUDRepository.findAll(), i get an exception if my object's class did not supply an empty constructor (I'm using spring data neo4j). For example, if i'll run, in spring-data-neo4j, the following command
, i will receive the following exception, if SomeObject did not declare an empty constructor:
Why is it happening? Maybe it must have an empty constructor for this scenario, because whenever it instantiate a new SomeObject object that way, it cannot infer the order of the parameters for the constructor. That's my guess at least.
Am i right?
Thanks!
As it seem to me, whenever i load objects from my database with CRUDRepository.findAll(), i get an exception if my object's class did not supply an empty constructor (I'm using spring data neo4j). For example, if i'll run, in spring-data-neo4j, the following command
Code:
Page<SomeObject> page = someClass.someObjects.findAll(new PageRequest(0, 10));
Code:
Exception in thread "main" org.springframework.dao.InvalidDataAccessApiUsageException: SomeObject: entity must have a no-arg constructor.; nested exception is java.lang.IllegalArgumentException: SomeObject: entity must have a no-arg constructor.
at org.springframework.data.neo4j.support.Neo4jExceptionTranslator.translateExceptionIfPossible(Neo4jExceptionTranslator.java:43)
at org.springframework.dao.support.ChainedPersistenceExceptionTranslator.translateExceptionIfPossible(ChainedPersistenceExceptionTranslator.java:58)
at org.springframework.dao.support.DataAccessUtils.translateIfNecessary(DataAccessUtils.java:213)
at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:163)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
at com.sun.proxy.$Proxy30.findAll(Unknown Source)
at org.technion.socialrescue.playground.Playground.main(Playground.java:33)
Caused by: java.lang.IllegalArgumentException: SomeObject: entity must have a no-arg constructor.
at org.springframework.data.neo4j.support.mapping.AbstractConstructorEntityInstantiator$1.create(AbstractConstructorEntityInstantiator.java:87)
at org.springframework.data.neo4j.support.mapping.AbstractConstructorEntityInstantiator.createEntityFromState(AbstractConstructorEntityInstantiator.java:56)
at org.springframework.data.neo4j.support.mapping.Neo4jEntityPersister$CachedInstantiator.createEntityFromState(Neo4jEntityPersister.java:135)
at org.springframework.data.neo4j.support.mapping.Neo4jEntityPersister$CachedInstantiator.createEntityFromState(Neo4jEntityPersister.java:122)
at org.springframework.data.neo4j.support.mapping.Neo4jEntityConverterImpl.read(Neo4jEntityConverterImpl.java:86)
at org.springframework.data.neo4j.support.mapping.Neo4jEntityPersister$CachedConverter.read(Neo4jEntityPersister.java:170)
at org.springframework.data.neo4j.support.mapping.Neo4jEntityPersister.createEntityFromState(Neo4jEntityPersister.java:189)
at org.springframework.data.neo4j.support.mapping.Neo4jEntityPersister.projectTo(Neo4jEntityPersister.java:216)
at org.springframework.data.neo4j.support.Neo4jTemplate.projectTo(Neo4jTemplate.java:197)
at org.springframework.data.neo4j.support.conversion.EntityResultConverter.doConvert(EntityResultConverter.java:68)
at org.springframework.data.neo4j.conversion.DefaultConverter.convert(DefaultConverter.java:43)
at org.springframework.data.neo4j.support.conversion.EntityResultConverter.convert(EntityResultConverter.java:99)
at org.springframework.data.neo4j.conversion.QueryResultBuilder$1.convert(QueryResultBuilder.java:102)
at org.springframework.data.neo4j.conversion.QueryResultBuilder$1.access$300(QueryResultBuilder.java:81)
at org.springframework.data.neo4j.conversion.QueryResultBuilder$1$1.underlyingObjectToObject(QueryResultBuilder.java:120)
at org.neo4j.helpers.collection.IteratorWrapper.next(IteratorWrapper.java:47)
at org.springframework.data.neo4j.repository.AbstractGraphRepository.subList(AbstractGraphRepository.java:406)
at org.springframework.data.neo4j.repository.AbstractGraphRepository.extractPage(AbstractGraphRepository.java:397)
at org.springframework.data.neo4j.repository.AbstractGraphRepository.findAll(AbstractGraphRepository.java:363)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.executeMethodOn(RepositoryFactorySupport.java:333)
at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.invoke(RepositoryFactorySupport.java:318)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:110)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:155)
... 4 more
Am i right?
Thanks!