I am getting the following exception while accessing my graph using Spring Data Neo4j:
SEVERE: Servlet.service() for servlet [appServlet] in context with path [/web] threw exception [Request processing failed; nested exception is org.springframework.dao.DataRetrievalFailureException: '__type__' on http://localhost:7474/db/data/relationship/125; nested exception is org.neo4j.graphdb.NotFoundException: '__type__' on http://localhost:7474/db/data/relationship/125] with root cause
org.neo4j.graphdb.NotFoundException: '__type__' on http://localhost:7474/db/data/relationship/125
at org.neo4j.rest.graphdb.entity.RestEntity.getProperty(RestEntity.java:97)
at org.springframework.data.neo4j.support.typerepresentation.AbstractIndexingTypeRepresentationStrategy.readAliasFrom(AbstractIndexingTypeRepresentationStrategy.java:110)
at org.springframework.data.neo4j.support.mapping.TRSTypeAliasAccessor.readAliasFrom(TRSTypeAliasAccessor.java:36)
at org.springframework.data.neo4j.support.mapping.TRSTypeAliasAccessor.readAliasFrom(TRSTypeAliasAccessor.java:26)
at org.springframework.data.convert.DefaultTypeMapper.readType(DefaultTypeMapper.java:102)
at org.springframework.data.convert.DefaultTypeMapper.getDefaultedTypeToBeUsed(DefaultTypeMapper.java:165)
at org.springframework.data.convert.DefaultTypeMapper.readType(DefaultTypeMapper.java:142)
at org.springframework.data.neo4j.support.mapping.Neo4jEntityConverterImpl.read(Neo4jEntityConverterImpl.java:78)
at org.springframework.data.neo4j.support.mapping.Neo4jEntityPersister$CachedConverter.read(Neo4jEntityPersister.java:170)
at org.springframework.data.neo4j.support.mapping.Neo4jEntityPersister.createEntityFromState(Neo4jEntityPersister.java:192)
at org.springframework.data.neo4j.support.Neo4jTemplate.createEntityFromState(Neo4jTemplate.java:181)
at org.springframework.data.neo4j.fieldaccess.GraphBackedEntityIterableWrapper.underlyingObjectToObject(GraphBackedEntityIterableWrapper.java:41)
at org.springframework.data.neo4j.fieldaccess.GraphBackedEntityIterableWrapper.underlyingObjectToObject(GraphBackedEntityIterableWrapper.java:27)
at org.neo4j.helpers.collection.IterableWrapper$MyIteratorWrapper.underlyingObjectToObject(IterableWrapper.java:57)
at org.neo4j.helpers.collection.IteratorWrapper.next(IteratorWrapper.java:47)
at org.neo4j.helpers.collection.IteratorUtil.addToCollection(IteratorUtil.java:353)
at org.neo4j.helpers.collection.IteratorUtil.addToCollection(IteratorUtil.java:370)
at org.springframework.data.neo4j.fieldaccess.RelatedToViaCollectionFieldAccessorFactory$RelatedToViaCollectionFieldAccessor.getValue(RelatedToViaCollectionFieldAccessorFactory.java:122)
at org.springframework.data.neo4j.fieldaccess.DefaultEntityState.getValue(DefaultEntityState.java:97)
at org.springframework.data.neo4j.support.mapping.SourceStateTransmitter.copyEntityStatePropertyValue(SourceStateTransmitter.java:90)
at org.springframework.data.neo4j.support.mapping.SourceStateTransmitter.access$000(SourceStateTransmitter.java:40)
at org.springframework.data.neo4j.support.mapping.SourceStateTransmitter$2.doWithAssociation(SourceStateTransmitter.java:61)
at org.springframework.data.mapping.model.BasicPersistentEntity.doWithAssociations(BasicPersistentEntity.java:269)
at org.springframework.data.neo4j.support.mapping.SourceStateTransmitter.copyPropertiesFrom(SourceStateTransmitter.java:57)
at org.springframework.data.neo4j.support.mapping.Neo4jEntityConverterImpl.loadEntity(Neo4jEntityConverterImpl.java:112)
at org.springframework.data.neo4j.support.mapping.Neo4jEntityConverterImpl.read(Neo4jEntityConverterImpl.java:104)
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.persist(Neo4jEntityPersister.java:244)
at org.springframework.data.neo4j.support.mapping.Neo4jEntityPersister.persist(Neo4jEntityPersister.java:231)
at org.springframework.data.neo4j.support.Neo4jTemplate.save(Neo4jTemplate.java:294)
at org.springframework.data.neo4j.support.Neo4jTemplate.save(Neo4jTemplate.java:288)
at org.springframework.data.neo4j.repository.AbstractGraphRepository.save(AbstractGraphRepository.java:110)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:622)
at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.executeMethodOn(RepositoryFactorySupport.java:344)
at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.invoke(RepositoryFactorySupport.java:329)
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)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
at com.sun.proxy.$Proxy36.save(Unknown Source)
My Nodes and relationships look like this :
#NodeEntity
public class User {
#GraphId
Long nodeId;
#Indexed(unique = true)
Long uid;
String name;
#RelatedTo(type="FRIENDS", direction=Direction.BOTH)
Set<User> friends;
#RelatedToVia(type="FRIENDS", elementClass=IsFriends.class)
Set<IsFriends> friendRelationships;
#RelatedTo(type="LIKES", direction=Direction.OUTGOING)
Set<Article> article;
#RelatedToVia(type="LIKES", elementClass=Reco.class)
Set<Likes> likeRelationships;
//getters and setters
..
..
}
From here : https://groups.google.com/forum/#!topic/neo4j/aFZCp5T3ABo
I do understand that there is some problem in defining both the RelatedTo and RelatedToVia fields in the NodeEntity class. As defined in the User class, the User has relationships with other Users by a #RelationshipEntity named FRIENDS and the user has relationships with other Articles (#NodeEntity) by a #RelationshipEntity named LIKES.
What is it that I am doing wrong ?
Related
one to many association is getting stack over flow error in groovy with grails. Please Check below classes, error log to see if there are any association.
errors.
This is what I tried so far:
Earlier association is from B to C class, now we modified it A to B class after making this association changes. Changes looks good to me but while accessing b's from A class its throwing stackoverflow error getBs method from A.groovy. If I remove getBs method its giving null as B even though b's available for that contract in db. Also calling B.findAllByContract dynamic finder method its throwing could not resolve property 'a' even though its available at class level. Could you please guide me here
class A implements Serializable {
static stampable = true
static auditable = true
static hasMany = [
bs: B]
static mapping = {
bs joinTable: [column: "a_id"]
}
static mappedBy = [ bs: "a"]
def getBs() {
println "calling ..."
return bs
}
}
class B implements Serializable {
A a
static constraints = {
a nullable:true
}
static mapping = {
sort title: "asc"
a column: "a_id"
}
static transients = ['BValue']
}
error log:
2021-03-28 13:06:10,825 {yyyy-MM-dd HH:mm:ss} admin ERROR org.apache.catalina.core.ContainerBase.[Tomcat].[localhost].[/app].[grailsDispatcherServlet] - Servlet.service() for servlet [grailsDispatcherServlet] in context with path [/app] threw exception [Handler processing failed; nested exception is java.lang.StackOverflowError] with root cause
java.lang.StackOverflowError: null
at org.codehaus.groovy.runtime.InvokerHelper.format(InvokerHelper.java:583)
at org.codehaus.groovy.runtime.InvokerHelper.format(InvokerHelper.java:575)
at org.codehaus.groovy.runtime.InvokerHelper.toString(InvokerHelper.java:130)
at org.codehaus.groovy.runtime.DefaultGroovyMethods.println(DefaultGroovyMethods.java:642)
at org.codehaus.groovy.runtime.dgm$504.invoke(Unknown Source)
at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite$PogoMetaMethodSiteNoUnwrapNoCoerce.invoke(PogoMetaMethodSite.java:251)
at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite.callCurrent(PogoMetaMethodSite.java:59)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:166)
at app.A.getBs(A.groovy:245)
at sun.reflect.GeneratedMethodAccessor878.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springsource.loaded.ri.ReflectiveInterceptor.jlrMethodInvoke(ReflectiveInterceptor.java:1426)
at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:93)
at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:325)
at groovy.lang.MetaClassImpl.getProperty(MetaClassImpl.java:1852)
at groovy.lang.ExpandoMetaClass.getProperty(ExpandoMetaClass.java:1155)
at groovy.lang.MetaClassImpl.getProperty(MetaClassImpl.java:3735)
at groovy.lang.ExpandoMetaClass.getProperty(ExpandoMetaClass.java:1167)
at org.codehaus.groovy.runtime.callsite.PogoMetaClassGetPropertySite.getProperty(PogoMetaClassGetPropertySite.java:51)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callGroovyObjectGetProperty(AbstractCallSite.java:307)
at app.A.getBs(A.groovy:246)
at sun.reflect.GeneratedMethodAccessor878.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springsource.loaded.ri.ReflectiveInterceptor.jlrMethodInvoke(ReflectiveInterceptor.java:1426)
at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:93)
at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:325)
at groovy.lang.MetaClassImpl.getProperty(MetaClassImpl.java:1852)
at groovy.lang.ExpandoMetaClass.getProperty(ExpandoMetaClass.java:1155)
at groovy.lang.MetaClassImpl.getProperty(MetaClassImpl.java:3735)
at groovy.lang.ExpandoMetaClass.getProperty(ExpandoMetaClass.java:1167)
at org.codehaus.groovy.runtime.callsite.PogoMetaClassGetPropertySite.getProperty(PogoMetaClassGetPropertySite.java:51)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callGroovyObjectGetProperty(AbstractCallSite.java:307)
at app.A.getBs(A.groovy:246)
at sun.reflect.GeneratedMethodAccessor878.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
Try updating the method getBs as follows:
def getBs() {
println "calling ..."
return this.bs
}
I think referring bs might be recursively calling getBs().
i've created a simple grails app with latest v3.2.6. created a Authors and Book classes in grails-app/domain.
book class in grails-app/domain looks like this ( i have a books class also )
package org.softwood
//Author has many books logical model
class Author {
String name
Collection books
//static hasMany = [books:Book]
static constraints = {
books nullable:true
}
}
and book domain class for completeness
package org.softwood
class Book {
String title
Author author
//static belongsTo = [author:Author]
static constraints = {
author nullable:true
}
}
I started app - no errors and tried to use grails console to create a instance of Author and got an error like this
java.lang.IllegalStateException: Either class [org.softwood.Author] is not a domain class or GORM has not been initialized correctly or has already been shutdown. Ensure GORM is loaded and configured correctly before calling any methods on a GORM entity.
so i edited BootStrap.groovy to try and create one at startup like this. Why does it not brought up Gorm correctly?
import org.softwood.*
class BootStrap {
def init = { servletContext ->
environments {
development{
createDevData()
}
test {}
production {}
}
}
def destroy = {
}
def createDevData() {
Author a = new Author(name:"will")
def res = a.save (flush:true, failOnExit:true)
assert res
assert Author.get(1).name == "will"
}
}
this errors when i start the app with same message, stack trace as follows
java.lang.IllegalStateException: Either class [org.softwood.Author] is not a domain class or GORM has not been initialized correctly or has already been shutdown. Ensure GORM is loaded and configured correctly before calling any methods on a GORM entity.
at org.grails.datastore.gorm.GormEnhancer.stateException(GormEnhancer.groovy:387)
at org.grails.datastore.gorm.GormEnhancer.findInstanceApi(GormEnhancer.groovy:273)
at org.grails.datastore.gorm.GormEnhancer.findInstanceApi(GormEnhancer.groovy:270)
at org.grails.datastore.gorm.GormEntity$Trait$Helper.currentGormInstanceApi(GormEntity.groovy:1326)
at org.grails.datastore.gorm.GormEntity$Trait$Helper.save(GormEntity.groovy:151)
at org.grails.datastore.gorm.GormEntity$Trait$Helper$save.call(Unknown Source)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:133)
at org.softwood.Author.save(Author.groovy)
at org.softwood.Author.save(Author.groovy)
at org.grails.datastore.gorm.GormEntity$save.call(Unknown Source)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:125)
at test.BootStrap.createDevData(BootStrap.groovy:21)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:93)
at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:325)
at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:384)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1024)
at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.callCurrent(PogoMetaClassSite.java:69)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:52)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:154)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:158)
at test.BootStrap$_closure1$_closure3$_closure4.doCall(BootStrap.groovy:10)
at test.BootStrap$_closure1$_closure3$_closure4.doCall(BootStrap.groovy)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:93)
at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:325)
at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:294)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1024)
at groovy.lang.Closure.call(Closure.java:414)
at groovy.lang.Closure.call(Closure.java:408)
at grails.util.Environment$EnvironmentBlockEvaluator.execute(Environment.java:529)
at grails.util.Environment.executeForEnvironment(Environment.java:510)
at grails.util.Environment.executeForCurrentEnvironment(Environment.java:485)
at org.grails.web.servlet.boostrap.DefaultGrailsBootstrapClass.callInit(DefaultGrailsBootstrapClass.java:62)
at org.grails.web.servlet.context.GrailsConfigUtils.executeGrailsBootstraps(GrailsConfigUtils.java:65)
at org.grails.plugins.web.servlet.context.BootStrapClassRunner.onStartup(BootStrapClassRunner.groovy:53)
at grails.boot.config.GrailsApplicationPostProcessor.onApplicationEvent(GrailsApplicationPostProcessor.groovy:256)
at grails.boot.config.GrailsApplicationPostProcessor.onApplicationEvent(GrailsApplicationPostProcessor.groovy)
at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:167)
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139)
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.boot.context.embedded.EmbeddedWebApplicationContext.finishRefresh(EmbeddedWebApplicationContext.java:144)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:545)
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:762)
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:372)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:316)
at grails.boot.GrailsApp.run(GrailsApp.groovy:83)
at grails.boot.GrailsApp.run(GrailsApp.groovy:388)
at grails.boot.GrailsApp.run(GrailsApp.groovy:375)
at grails.boot.GrailsApp$run.call(Unknown Source)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:133)
at test.Application.main(Application.groovy:8)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)
try with this
package org.softwood
//Author has many books logical model
class Author {
String name
//Collection books
static hasMany = [books:Book]
static constraints = {
books nullable:true // you may not need this.
}
}
I am using Spring-data-neo4j but meet the following problem.
Everything works fine until I want to cast the queried LinkedHashMap to an #NodeEntity. Here's the code
Movie.class
#NodeEntity
public class Movie {
#GraphId Long id;
#Property(name="title")
private String mtitle;
#Property(name="released")
private String mreleased;
#Property(name="tagline")
private String mtagline;
#Relationship(type = "REVIEWED", direction = Relationship.INCOMING)
private Set<Movie> reviewed;
#Relationship(type = "ACTED_IN", direction = Relationship.INCOMING)
private Set<Movie> actedIn;
#Relationship(type = "DIRECTED", direction = Relationship.INCOMING)
private Set<Movie> directed;
}
They repository
#Repository
public interface MovieRepository extends GraphRepository<Movie>{
#Query("MATCH (n) WHERE id(n)={0} RETURN n")
Movie getMovieFromId(Integer idOfMovie);
}
When using getMovieFromId() in the service, I get the exception:
java.lang.ClassCastException: java.util.LinkedHashMap cannot be cast to com.hersbitcloud.cancercloud.domain.Movie
com.sun.proxy.$Proxy55.getMovieFromId(Unknown Source)
com.hersbitcloud.cancercloud.services.GLService.getGL(GLService.java:24)
com.hersbitcloud.cancercloud.controllers.GLController.getGLOverview(GLController.java:22)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
java.lang.reflect.Method.invoke(Method.java:497)
org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:222)
org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:137)
org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:110)
org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:814)
org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:737)
org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85)
org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:959)
org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:893)
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970)
org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:861)
javax.servlet.http.HttpServlet.service(HttpServlet.java:622)
org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:77)
org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
org.springframework.web.filter.HttpPutFormContentFilter.doFilterInternal(HttpPutFormContentFilter.java:87)
org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
The movie node in the neo4j contains property 'title', 'released', 'tagline', and relationship 'ACTED_IN', 'DIRECTED' and 'REVIEWED'.
BTW, if I change the repository type from Movie to HashMap, the exception gone.
Any help will be appreciated.
Please check if the Movie package is included in the ones supplied to SessionFactory. The OGM will map to the entity if it knows that it's a domain entity (i.e. scanned when the SessionFactory is instantiated), otherwise, it'll just send back the Map of data.
I have a custom converter annotated as a #Component and it depends on MyBean which is injected by Spring via #Autowired at boot time.
MyEntity has a field MyObject to be converted by that converter. OGM will call toEntityAttribute from MyObjectToStringConverter as soon as I retrieve MyEntity from Neo4j. However, I'm getting a NPE. It seems OGM does not reuse my converter created by Spring and MyBean dependency is always NULL.
Should OGM be able to get my converter from Spring context?
Is there a way MyBean could be initialized by OGM?
If not, can I register a converter by myselft?
#NodeEntity
class MyEntity {
#Convert(MyObjectToStringConverter.class)
private MyObject myObject;
...
}
#Component
class MyObjectToStringConverter implements AttributeConverter<MyObject, String> {
#Autowired
private MyBean myBean;
#Override
public String toGraphProperty(MyObject value) {
return value.getName();
}
#Override
public MyObject toEntityAttribute(String value) {
return myBean.convert(value); // myBean is NULL
}
}
...
repository.find(myEntityID) // NPE from MyObjectToStringConverter
java.lang.NullPointerException: null
at org.myproject.mvc.converter.MyObjectToStringConverter.toEntityAttribute(MyObjectToStringConverter.java:25)
at org.myproject.mvc.converter.MyObjectToStringConverter.toEntityAttribute(MyObjectToStringConverter.java:12)
at org.neo4j.ogm.entityaccess.FieldWriter.write(FieldWriter.java:64)
at org.neo4j.ogm.mapper.GraphEntityMapper.writeProperty(GraphEntityMapper.java:162)
at org.neo4j.ogm.mapper.GraphEntityMapper.setProperties(GraphEntityMapper.java:127)
at org.neo4j.ogm.mapper.GraphEntityMapper.mapNodes(GraphEntityMapper.java:108)
at org.neo4j.ogm.mapper.GraphEntityMapper.mapEntities(GraphEntityMapper.java:92)
at org.neo4j.ogm.mapper.GraphEntityMapper.map(GraphEntityMapper.java:67)
at org.neo4j.ogm.session.response.SessionResponseHandler.loadById(SessionResponseHandler.java:161)
at org.neo4j.ogm.session.delegates.LoadOneDelegate.load(LoadOneDelegate.java:45)
at org.neo4j.ogm.session.delegates.LoadOneDelegate.load(LoadOneDelegate.java:36)
at org.neo4j.ogm.session.Neo4jSession.load(Neo4jSession.java:99)
at org.springframework.data.neo4j.repository.GraphRepositoryImpl.findOne(GraphRepositoryImpl.java:60)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.executeMethodOn(RepositoryFactorySupport.java:483)
at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.doInvoke(RepositoryFactorySupport.java:468)
at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.invoke(RepositoryFactorySupport.java:440)
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.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:99)
at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:281)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:136)
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:208)
at com.sun.proxy.$Proxy87.findOne(Unknown Source)
at org.myproject.mvc.service.AbstractService.find(AbstractService.java:40)
The OGM will not get the converter from the Spring context- it has no dependencies at all on Spring. Perhaps you can use Springs ConversionService?
http://docs.spring.io/spring-data/neo4j/docs/4.0.0.RELEASE/reference/html/#_spring_s_conversionservice
I tried something like this but still throwing NullPointerException
#RunWith(MockitoJUnitRunner.class)
public class MyActionTest extends BaseActionTestCase {
#Mock private ServletActionContext context;
#Mock
private serviceclass serviceMock;
#InjectMocks
private MyAction action;
#Test
public void testSave() throws Exception {
when(serviceMock.getTaskCode()).thenReturn("tc");
action.save();
verify(serviceMock).saveObject(any(Task.class));
}
posting stacktrace:
java.lang.NullPointerException
at org.apache.struts2.ServletActionContext.getRequest(ServletActionContext.java:112)
at com.princess.ilo.webapp.action.BaseAction.getRequest(BaseAction.java:176)
at com.princess.ilo.webapp.action.BaseAction.getSession(BaseAction.java:198)
at com.princess.ilo.webapp.action.BaseAction.getUser(BaseAction.java:206)
at com.princess.ilo.webapp.action.TaskAction.save(TaskAction.java:116)
at com.princess.ilo.webapp.action.TaskActionTest.testSave(TaskActionTest.java:97)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
at org.junit.runners.BlockJUnit4ClassRunner.runNotIgnored(BlockJUnit4ClassRunner.java:79)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:71)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:49)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
at org.mockito.internal.runners.JUnit45AndHigherRunnerImpl.run(JUnit45AndHigherRunnerImpl.java:37)
at org.mockito.runners.MockitoJUnitRunner.run(MockitoJUnitRunner.java:62)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests
hm, I would say you still need to create the action object, like
#InjectMocks private MyAction action = new MyAction();
see http://docs.mockito.googlecode.com/hg/org/mockito/InjectMocks.html for some examples