question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

MappingException when querying object with List<Enum> using Embedded

See original GitHub issue

Expected Behavior

Using the EmbeddedDriver, I should be able to query for an Entity with a Collection of Enums without issue. These Enums should be able to have instance fields.

Current Behavior

public class Person extends Entity {
    List<RoleType> roleTypes;
    // getters and setters
}

public enum RoleType {
    DEVELOPER("dev"),
    ARCHITECT("arch"),
    MANAGER("mgr");

    private String value;

    public String getValue() {
        return value;
    }

    RoleType(String value) {
        this.value = value;
    }
}

Now, consider the following two session query methods:

// call this "method1"
<T> Iterable<T> query(Class<T> objectType, String cypher, Map<String, ?> parameters);

// call this "method2"
Result query(String cypher, Map<String, ?> parameters);

When using method1, there are no issues. However, method2 breaks when trying to map the roleTypes field to the Person entity (Caused by: java.lang.ClassCastException: [Ljava.lang.String; cannot be cast to java.util.Collection).

Note that I’ve only seen this on Embedded (so far). This also happens if a List<Long> field is persisted as an empty ArrayList.

Steps to Reproduce (for bugs)

Link to repo demonstrating problem (please PM me for access): https://github.com/jaredhancock31/cisco-sdn4/tree/listEnums

  1. save entity with collection of enums with instance strings.
  2. using the query api that does not require expected return type, send a query that will return the object in question.

Stacktrace:

Caused by: org.neo4j.ogm.exception.MappingException: Error mapping GraphModel to instance of com.cisco.example.domain.Person at org.neo4j.ogm.context.GraphEntityMapper.mapEntities(GraphEntityMapper.java:138) ~[neo4j-ogm-core-2.1.2.jar:na] at org.neo4j.ogm.context.GraphEntityMapper.map(GraphEntityMapper.java:110) ~[neo4j-ogm-core-2.1.2.jar:na] at org.neo4j.ogm.context.GraphEntityMapper.map(GraphEntityMapper.java:105) ~[neo4j-ogm-core-2.1.2.jar:na] at org.neo4j.ogm.context.RestModelMapper.mapEntity(RestModelMapper.java:157) ~[neo4j-ogm-core-2.1.2.jar:na] at org.neo4j.ogm.context.RestModelMapper.map(RestModelMapper.java:76) ~[neo4j-ogm-core-2.1.2.jar:na] at org.neo4j.ogm.session.delegates.ExecuteQueriesDelegate.query(ExecuteQueriesDelegate.java:102) ~[neo4j-ogm-core-2.1.2.jar:na] at org.neo4j.ogm.session.delegates.ExecuteQueriesDelegate.query(ExecuteQueriesDelegate.java:81) ~[neo4j-ogm-core-2.1.2.jar:na] at org.neo4j.ogm.session.Neo4jSession.query(Neo4jSession.java:392) ~[neo4j-ogm-core-2.1.2.jar:na] at com.cisco.example.Application.lambda$demo$0(Application.java:86) [main/:na] at org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:776) [spring-boot-1.5.2.RELEASE.jar:1.5.2.RELEASE] ... 11 common frames omitted Caused by: java.lang.ClassCastException: [Ljava.lang.String; cannot be cast to java.util.Collection at org.neo4j.ogm.entity.io.EntityAccess.merge(EntityAccess.java:73) ~[neo4j-ogm-core-2.1.2.jar:na] at org.neo4j.ogm.entity.io.EntityAccess.merge(EntityAccess.java:39) ~[neo4j-ogm-core-2.1.2.jar:na] at org.neo4j.ogm.context.GraphEntityMapper.writeProperty(GraphEntityMapper.java:226) ~[neo4j-ogm-core-2.1.2.jar:na] at org.neo4j.ogm.context.GraphEntityMapper.setProperties(GraphEntityMapper.java:184) ~[neo4j-ogm-core-2.1.2.jar:na] at org.neo4j.ogm.context.GraphEntityMapper.mapNodes(GraphEntityMapper.java:151) ~[neo4j-ogm-core-2.1.2.jar:na] at org.neo4j.ogm.context.GraphEntityMapper.mapEntities(GraphEntityMapper.java:135) ~[neo4j-ogm-core-2.1.2.jar:na] ... 20 common frames omitted

Context

We use a few queries that don’t want to pass in an expected return type, as the data being returned may not be uniform in type.

Your Environment

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
frant-hartmcommented, May 25, 2017

It is available in 2.1.3-SNAPSHOT. We will be releasing 2.1.3 tomorrow.

0reactions
fairy3commented, May 25, 2017

Sure

Read more comments on GitHub >

github_iconTop Results From Across the Web

Morphia Interface for List of enum does not work ...
I tried creating a Custom Converter: public class InfoChartInformationMorphiaConverter extends TypeConverter{ public ...
Read more >
Hibernate ORM 5.4.33.Final User Guide
Hibernate is an Object/Relational Mapping solution for Java environments. ... Hibernate supports the mapping of Java enums as basic value types in a...
Read more >
Spring Data R2DBC - Reference Documentation
Repository Methods Returning Collections or Iterables. Query methods that return multiple results can use standard Java Iterable , List , and ...
Read more >
Persisting Enums in JPA
A quick and practical guide to persisting enums in JPA. ... DDL and SQL statements, DTO objects, and MapStruct interfaces.
Read more >
Reference - OGM Library
Neo4j-OGM is a fast object-graph mapping library for Neo4j, optimised for ... neo4j-ogm-embedded-driver - Creates an in-memory Neo4j instance and uses it.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found