简体   繁体   English

SDN4:ClassCastException:无法将java.util.HashMap强制转换为[EntityNode]

[英]SDN4: ClassCastException: java.util.HashMap cannot be cast to [EntityNode]

An issue has appeared for our code after updating to SDN4: 更新到SDN4后,我们的代码出现了一个问题:

 java.lang.ClassCastException: java.util.HashMap cannot be cast to com.example.server.model.neo4j.node.Item
    at  com.example.server.service.relationship.friend.FriendRelationshipService.getSkillUuidByPotentialSkillName (FriendRelationshipService.java:257)
    at com.example.server.service.relationship.friend.FriendRelationshipService.createFriendRequestRelationshipBetweenPeople(FriendRelationshipService.java:211)
    at com.example.server.service.relationship.friend.FriendRelationshipService.sendFriendRequestHelper(FriendRelationshipService.java:171)
    at com.example.server.service.relationship.friend.FriendRelationshipService.sendFriendRequest(FriendRelationshipService.java:81)
    at com.example.server.test.integration.controller.api.friends.TestLoadFriendRequestsBothWays.testLoadFriendRequestsBothWaysNullCommonSkillNameSupplied(TestLoadFriendRequestsBothWays.java:184)
    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:606)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
    at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
    at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:74)
    at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:85)
    at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:86)
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:243)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:88)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
    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:363)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:182)
    at org.junit.runners.Suite.runChild(Suite.java:128)
    at org.junit.runners.Suite.runChild(Suite.java:27)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
    at org.junit.runners.Suite.runChild(Suite.java:128)
    at org.junit.runners.Suite.runChild(Suite.java:27)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
    at org.junit.runners.Suite.runChild(Suite.java:128)
    at org.junit.runners.Suite.runChild(Suite.java:27)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
    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:459)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)

The code that causes the exception is below: 导致异常的代码如下:

 Iterable<Item> items = itemRepository.findItemsByPerson(person.getUuid(), new Pagination(0, 1));
 for(Item item : items) { // Stacktrace leads the issue to here.
    currItem = item; 
    break;
 }

Perhaps this is something to do with the for-each loop, as this appears to be the case for other parts of the code which also shows this issue. 也许这与for-each循环有关,因为代码的其他部分似乎也是如此,这也显示了此问题。

Update 05/08/2015 : The Item class is as below: 更新05/08/2015 :Item类如下:

@NodeEntity
public class Item extends Entity implements Packageable {

    private String name; 

    private String shortDescription;

    private boolean isUserCreatedItem = false; 

    private double timestamp;

    @Relationship(type = "CREATED_BY")
    private Person creator;

    public Item() {

    }

    /**
     * This should be called after instantiating a new node (indicating a new node is to be added to the database)
     */
    @Override
    public void init() {
        super.init();
    }

// Other methods here

}

And the Entity class: 和Entity类:

public abstract class Entity {

    private String uuid;    
    @GraphId private Long id;

    public void init() {
        // generate the UUID
        if(uuid == null) {
            uuid = Util.generateUUID();
        }
    }
}

The repository query method: 存储库查询方法:

@Query("MATCH (item)<-[:HAS_ITEM]-(you {uuid: {0}}) "
        + "RETURN DISTINCT item "
        + "ORDER BY item.name")
Iterable<Item> findItemsByPerson(String personUuid);

Any help would be much appreciated. 任何帮助将非常感激。

Cheers 干杯

This is a bug which you can track at https://jira.spring.io/browse/DATAGRAPH-727 您可以在https://jira.spring.io/browse/DATAGRAPH-727上跟踪此错误。

As a temporary workaround, please use a Collection instead of an Iterable . 作为临时的解决方法,请使用Collection而不是Iterable

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 FlexJson 错误:ClassCastException:java.util.HashMap 无法转换为类 - FlexJson Error : ClassCastException: java.util.HashMap cannot be cast to class java.lang.ClassCastException: java.util.HashMap$EntrySet 不能转换为 java.util.Map$Entry - java.lang.ClassCastException: java.util.HashMap$EntrySet cannot be cast to java.util.Map$Entry java.lang.ClassCastException:java.util.HashMap $ EntrySet无法转换为java.util.HashSet - java.lang.ClassCastException: java.util.HashMap$EntrySet cannot be cast to java.util.HashSet java.lang.ClassCastException:无法将java.util.HashMap强制转换为java.lang.String - java.lang.ClassCastException: java.util.HashMap cannot be cast to java.lang.String java.lang.ClassCastException:无法将java.util.HashMap强制转换为com.jms.testing.spring.InstructionMessage - java.lang.ClassCastException: java.util.HashMap cannot be cast to com.jms.testing.spring.InstructionMessage java.lang.ClassCastException:java.util.HashMap无法强制转换为java.lang.Comparable - java.lang.ClassCastException: java.util.HashMap cannot be cast to java.lang.Comparable java.lang.ClassCastException:java.util.HashMap无法转换为自定义数据类 - java.lang.ClassCastException: java.util.HashMap cannot be cast to custom data class java.lang.ClassCastException: class java.util.Z063A5BC470661C3C7909 无法转换 - java.lang.ClassCastException: class java.util.HashMap cannot be cast : SpringBoot 无法将java.util.HashMap强制转换为java.util.ArrayList - java.util.HashMap cannot be cast to java.util.ArrayList java.util.hashmap无法转换为java.util.list - java.util.hashmap cannot be cast to java.util.list
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM