Class Cast Exception - from GraphBackedEntityIterableWrapper to my class

49 views
Skip to first unread message

Chris

unread,
Apr 25, 2012, 11:50:33 AM4/25/12
to ne...@googlegroups.com
I'm using Spring Data Neo4j 2.0.1.release and my unit test creates a relationship between two of instances of my class Resource.  The ResourceRelationship class only has the start and end node and in my Resource class I store all the relationships like so
@RelatedToVia
Collection<ResourceRelationship> relations;

// and the method to get the relationships
public Collection<ResourceRelationship> getResourceRelationships()
{
    return IteratorUtil.asCollection(relations);
}

Creating the relationships works and before the return executes I can see relations is not empty.  In my unit test the error is thrown when i call rr.getInterator().next()
Resource found = resourceRepository.findByName("TestResource"); // this finds the correct resource
Collection<ResourceRelationship> rr = found.getResourceRelationships(); // collection is not empty
// i tried looping here but will still throw error
ResourceRelationship resR = rr.getIterator().next(); // throws class cast exception error

When I step thru in debug I can see the target class is my ResourceRelationship class but when I continue stepping in I eventually hit a source not found and can't debug any further. test fails with this stack trace

java.lang.ClassCastException: org.springframework.data.neo4j.fieldaccess.GraphBackedEntityIterableWrapper cannot be cast to jackal.mytest.domain.ResourceRelationship
    at jackal.mytest.domain.DomainTest.resourcesCanBeLinked(DomainTest.java:59)
    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:601)
    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.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:74)
    at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:82)
    at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:72)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:231)
    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.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
    at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:174)
    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(RemoteTestRunner.java:683)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)

Thank you for any guidance!

Michael Hunger

unread,
Apr 25, 2012, 12:01:12 PM4/25/12
to ne...@googlegroups.com
Chris could you perhaps share the project with me to investigate?

Michael

Sent from mobile device
Message has been deleted

Chris

unread,
Apr 25, 2012, 1:58:13 PM4/25/12
to ne...@googlegroups.com
Turns out I was missing an elementClass = classtype in my annotation. problem solved.


On Wednesday, April 25, 2012 12:01:12 PM UTC-4, Michael Hunger wrote:
Chris could you perhaps share the project with me to investigate?

Michael

Sent from mobile device

Michael Hunger

unread,
Apr 25, 2012, 2:06:30 PM4/25/12
to ne...@googlegroups.com
great that you figured it out.

Cheers

Michael
Reply all
Reply to author
Forward
0 new messages