Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MappingException when querying object with List<Enum> using Embedded #2

Merged
merged 2 commits into from
May 16, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions issue-359/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Repro project for issue-359

## Configuring

First, check out and update the versions in the `pom.xml` to match yours

- the `neo4j-ogm.version`

You can also override the version of Neo4j java drivers.

## Logging

This project contains a `logback-test.xml` file in `src/test/resources` that you
may wish to configure to emit more detailed logging.
67 changes: 67 additions & 0 deletions issue-359/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<artifactId>issue-359</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>jar</packaging>

<name>Neo4j OGM 2.x Test Case Template</name>
<description>Use this template to report bugs with Neo4j OGM</description>

<parent>
<groupId>org.neo4j.ogm.testcasetemplate</groupId>
<artifactId>testcasetemplate</artifactId>
<version>1.0.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

<properties>

<!-- change with your versions here -->
<neo4j-ogm.version>2.1.2</neo4j-ogm.version>

<!-- if overriding the driver version, also uncomment the driver dependency below -->
<!--<neo4j-java-driver.version>1.2.2</neo4j-java-driver.version>-->
</properties>

<dependencies>
<!--<dependency>-->
<!--<groupId>org.neo4j.driver</groupId>-->
<!--<artifactId>neo4j-java-driver</artifactId>-->
<!--<version>${neo4j-java-driver.version}</version>-->
<!--</dependency>-->
<dependency>
<groupId>org.neo4j</groupId>
<artifactId>neo4j-ogm-core</artifactId>
<version>2.1.2</version>
</dependency>
<dependency>
<groupId>org.neo4j</groupId>
<artifactId>neo4j-ogm-embedded-driver</artifactId>
<version>2.1.2</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.neo4j</groupId>
<artifactId>neo4j-ogm-http-driver</artifactId>
<version>2.1.2</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.neo4j</groupId>
<artifactId>neo4j-ogm-test</artifactId>
<version>2.1.2</version>
<scope>test</scope>
<exclusions> <!-- necessary to get logs in tests -->
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-nop</artifactId>
</exclusion>
</exclusions>
</dependency>

</dependencies>

</project>
23 changes: 23 additions & 0 deletions issue-359/src/main/java/org/neo4j/ogm/test/domain/Role.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package org.neo4j.ogm.test.domain;

/**
* @author jarhanco
*/
public enum Role {
MANAGER("manager"),
ARCHITECT("architect"),
DEV("dev"),
INTERN("intern");

private String value;

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

public String getValue() {
return this.value;
}


}
55 changes: 55 additions & 0 deletions issue-359/src/main/java/org/neo4j/ogm/test/domain/User.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package org.neo4j.ogm.test.domain;

import org.neo4j.ogm.annotation.GraphId;
import org.neo4j.ogm.annotation.NodeEntity;

import java.util.List;

@NodeEntity
public class User {

@GraphId
private Long id;

private String firstName;

private String lastName;

private List<Role> roles;

private String email;

public User() {
// required by
}

public User(String email, String firstName, String lastName) {
this.firstName = firstName;
this.lastName = lastName;
this.email = email;
}

public Long getId() {
return this.id;
}

public String getFirstName() {
return firstName;
}

public String getLastName() {
return lastName;
}

public String getEmail() {
return email;
}

public List<Role> getRoles() {
return roles;
}

public void setRoles(List<Role> roles) {
this.roles = roles;
}
}
61 changes: 61 additions & 0 deletions issue-359/src/test/java/org/neo4j/ogm/test/OgmTestCase.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package org.neo4j.ogm.test;

import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.neo4j.harness.junit.Neo4jRule;
import org.neo4j.ogm.model.Result;
import org.neo4j.ogm.session.Session;
import org.neo4j.ogm.session.SessionFactory;
import org.neo4j.ogm.test.domain.Role;
import org.neo4j.ogm.test.domain.User;

import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;

import static org.assertj.core.api.Assertions.assertThat;

public class OgmTestCase {

@Rule
public Neo4jRule neoServer = new Neo4jRule();
private Session session;

@Before
public void setUp() throws Exception {

org.neo4j.ogm.config.Configuration configuration = new org.neo4j.ogm.config.Configuration();
configuration.driverConfiguration()
.setDriverClassName("org.neo4j.ogm.drivers.embedded.driver.EmbeddedDriver");

SessionFactory sessionFactory = new SessionFactory(configuration, "org.neo4j.ogm.test.domain");
session = sessionFactory.openSession();
session.purgeDatabase();
}

@Test
public void sampleTest() {
User user = new User("noone@nowhere.com", "No", "One");
session.save(user);

user.setRoles(Arrays.asList(Role.ARCHITECT, Role.DEV));
session.save(user);
session.clear();

user = session.load(User.class, user.getId(), 0);
assertThat(!user.getRoles().isEmpty());
session.clear();

// observe proper behavior
Iterable<User> result1 = session.query(User.class, "MATCH (n:User) WHERE ID(n)=" + user.getId() + " RETURN n", Collections.EMPTY_MAP);
assertThat(!result1.iterator().next().getRoles().isEmpty());
session.clear();

// classCastException here
Result result2 = session.query("MATCH (n:User) WHERE ID(n)=" + user.getId() + " RETURN n", Collections.EMPTY_MAP);
assertThat(null != result2);


}
}
29 changes: 29 additions & 0 deletions issue-359/src/test/resources/logback-test.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright (c) 2002-2016 "Neo Technology,"
~ Network Engine for Objects in Lund AB [http://neotechnology.com]
~
~ This product is licensed to you under the Apache License, Version 2.0 (the "License").
~ You may not use this product except in compliance with the License.
~
~ This product may include a number of subcomponents with
~ separate copyright notices and license terms. Your use of the source
~ code for these subcomponents is subject to the terms and
~ conditions of the subcomponent's license, as noted in the LICENSE file.
-->

<configuration>

<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d %5p %40.40c:%4L - %m%n</pattern>
</encoder>
</appender>

<logger name="org.neo4j.ogm" level="debug"/>

<root level="warn">
<appender-ref ref="console"/>
</root>

</configuration>
14 changes: 14 additions & 0 deletions issue-361/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Repro project for issue-361

## Configuring

First, check out and update the versions in the `pom.xml` to match yours

- the `neo4j-ogm.version`

You can also override the version of Neo4j java drivers.

## Logging

This project contains a `logback-test.xml` file in `src/test/resources` that you
may wish to configure to emit more detailed logging.
67 changes: 67 additions & 0 deletions issue-361/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<artifactId>issue-359</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>jar</packaging>

<name>Neo4j OGM 2.x Test Case Template</name>
<description>Use this template to report bugs with Neo4j OGM</description>

<parent>
<groupId>org.neo4j.ogm.testcasetemplate</groupId>
<artifactId>testcasetemplate</artifactId>
<version>1.0.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

<properties>

<!-- change with your versions here -->
<neo4j-ogm.version>2.1.2</neo4j-ogm.version>

<!-- if overriding the driver version, also uncomment the driver dependency below -->
<!--<neo4j-java-driver.version>1.2.2</neo4j-java-driver.version>-->
</properties>

<dependencies>
<!--<dependency>-->
<!--<groupId>org.neo4j.driver</groupId>-->
<!--<artifactId>neo4j-java-driver</artifactId>-->
<!--<version>${neo4j-java-driver.version}</version>-->
<!--</dependency>-->
<dependency>
<groupId>org.neo4j</groupId>
<artifactId>neo4j-ogm-core</artifactId>
<version>2.1.2</version>
</dependency>
<dependency>
<groupId>org.neo4j</groupId>
<artifactId>neo4j-ogm-embedded-driver</artifactId>
<version>2.1.2</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.neo4j</groupId>
<artifactId>neo4j-ogm-http-driver</artifactId>
<version>2.1.2</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.neo4j</groupId>
<artifactId>neo4j-ogm-test</artifactId>
<version>2.1.2</version>
<scope>test</scope>
<exclusions> <!-- necessary to get logs in tests -->
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-nop</artifactId>
</exclusion>
</exclusions>
</dependency>

</dependencies>

</project>
48 changes: 48 additions & 0 deletions issue-361/src/main/java/org/neo4j/ogm/test/domain/Company.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package org.neo4j.ogm.test.domain;

import org.neo4j.ogm.annotation.GraphId;
import org.neo4j.ogm.annotation.NodeEntity;

import java.util.List;

/**
* @author jarhanco
*/
@NodeEntity
public class Company {

@GraphId
private Long id;

private User owner;

private List<User> staff;


public Company() {
}

public Company(User owner) {
this.owner = owner;
}

public Long getId() {
return id;
}

public User getOwner() {
return owner;
}

public void setOwner(User owner) {
this.owner = owner;
}

public List<User> getStaff() {
return staff;
}

public void setStaff(List<User> staff) {
this.staff = staff;
}
}
Loading