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

Session.delete method throws exception when deleting array of entities #509

Closed
chomnoue opened this issue Aug 13, 2018 · 1 comment · Fixed by #512
Closed

Session.delete method throws exception when deleting array of entities #509

chomnoue opened this issue Aug 13, 2018 · 1 comment · Fixed by #512
Assignees

Comments

@chomnoue
Copy link

Expected Behavior

org.neo4j.ogm.session.Session#delete(T) must be able to delete an array of entities,
as declared in the javadoc:
@param object object to delete, may be single entity, array of entities or {@link Iterable}

Current Behavior

java.lang.IllegalArgumentException is thrown when one tries to save an array of entities.

Possible Solution

In DeleteDelegate.deletAll(T) the array is added to a collection as a single object.
It should instead be copied element by element just like in SaveDelegate.save()

Steps to Reproduce (for bugs)

Here is a sample code you can use to reproduce the issue.

  1. Create a project with the following dependencies:
    build.gradle
compile("org.neo4j:neo4j-ogm-core:3.1.0")
runtime ("org.neo4j:neo4j-ogm-embedded-driver:3.1.0")
runtime("org.neo4j:neo4j:3.4.4")
  1. Add an entity class
    movies.domain.Actor.java
package movies.domain;

import org.neo4j.ogm.annotation.GeneratedValue;
import org.neo4j.ogm.annotation.Id;
import org.neo4j.ogm.annotation.NodeEntity;

@NodeEntity
public class Actor {

  @Id
  @GeneratedValue
  private Long id;

  public Long getId() {
    return id;
  }

  public void setId(Long id) {
    this.id = id;
  }
}
  1. Add a main class to save and delete entities
    movies.Main.java
package movies;

import movies.domain.Actor;
import org.neo4j.ogm.config.Configuration;
import org.neo4j.ogm.session.Session;
import org.neo4j.ogm.session.SessionFactory;

public class Main {

  public static void main(String[] args) {
    Configuration configuration = new Configuration.Builder().build();
    SessionFactory sessionFactory = new SessionFactory(configuration, "movies.domain");
    Session session = sessionFactory.openSession();

    Actor actor1= new Actor();
    Actor actor2= new Actor();

    session.save(new Actor[]{actor1, actor2});

    session.delete(new Actor[]{actor1, actor2});
  }
}
  1. When you run the Main class, you should get an exception like the following:
Exception in thread "main" java.lang.IllegalArgumentException: Class class [Lmovies.domain.Actor; is not a valid entity class. Please check the entity mapping.
        at org.neo4j.ogm.context.MappingContext.nativeId(MappingContext.java:489)
        at org.neo4j.ogm.context.MappingContext.neighbours(MappingContext.java:381)
        at org.neo4j.ogm.session.delegates.DeleteDelegate.deleteAll(DeleteDelegate.java:71)
        at org.neo4j.ogm.session.delegates.DeleteDelegate.delete(DeleteDelegate.java:79)
        at org.neo4j.ogm.session.Neo4jSession.delete(Neo4jSession.java:449)
        at movies.Main.main(Main.java:20)

Context

In my project, I am trying to provide a library for developers to easily manage a graph for a specific domain using neo4j OGM.

Your Environment

@meistermeier
Copy link
Collaborator

Thanks for reporting this issue and providing a sample project. We will inspect this.

@meistermeier meistermeier self-assigned this Aug 22, 2018
meistermeier added a commit that referenced this issue Aug 22, 2018
The array object is taken as an single object into a new list.
This causes operations to fail because they try to resolve e.g. the id
of an array object instead of the every single entry.

Fixes #509
meistermeier added a commit that referenced this issue Sep 3, 2018
The array object is taken as an single object into a new list.
This causes operations to fail because they try to resolve e.g. the id
of an array object instead of the every single entry.

Fixes #509
meistermeier added a commit that referenced this issue Sep 3, 2018
The array object is taken as an single object into a new list.
This causes operations to fail because they try to resolve e.g. the id
of an array object instead of the every single entry.

Fixes #509
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants