Skip to content

saveAll use the lowest common denominator for determining the entity type to be saved. #2326

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

Closed
LGDOI opened this issue Jul 13, 2021 · 4 comments
Assignees
Labels
type: bug A general bug

Comments

@LGDOI
Copy link

LGDOI commented Jul 13, 2021

Given a list of entities with mixed types which have common parent.

e.g.,
Base class does NOT have @Node annotation

public abstract class BaseEntity {}

Entity classes have @Node annotation

public abstract class Animal extends BaseEntity {}
public abstract class Pet extends Animal {
  public static  class Cat extends Pet {}
  public static  class Dog extends Pet {}
}

Repository class

public interface AnimalRepository extends Neo4jRepository<Animal, String> {}

List of animals

List<Animal> animals = List.of(new Cat(), new Dog());

Save iteratively

animals.forEach(animalRepository::save);

Two nodes created with all labels (Animal, Pet, Cat, Dog) correctly as expected

Save the list with saveAll does not save correctly.

animalRepository.saveAll(animals);

Two nodes are created but these nodes only have a label of BaseEntity.

Expected behavior

The saveAll() method with mixed entity type should create exact same labels as save().

version 6.1.1

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Jul 13, 2021
@michael-simons michael-simons self-assigned this Jul 14, 2021
@michael-simons
Copy link
Collaborator

I assume you mean @Node annotation, right? There is no @Entity annotation.

@michael-simons
Copy link
Collaborator

Anyway, I can confirm this,

@michael-simons michael-simons changed the title save and saveAll methods behave differently saveAll methods use the lowest common denominator for determining the entity type to be saved. Jul 14, 2021
@michael-simons michael-simons changed the title saveAll methods use the lowest common denominator for determining the entity type to be saved. saveAll use the lowest common denominator for determining the entity type to be saved. Jul 14, 2021
@michael-simons michael-simons added type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged labels Jul 14, 2021
michael-simons added a commit that referenced this issue Jul 14, 2021
collection is persisted.

In case a heterogeneous is persisted via `saveAll` on a repository or
any of the templates, we do fall back to individual statements to
persist its content the same way we handle dynamic labels, versioned
entities or entities with generated ids.

The reason for this is simple: We need the exact entity to determine
labels in an inheritance hierachy, otherwise only the information given
by the lowest common denominator will be considered, effectively leading
to `saveAll` behaving different than `save`.

This fixes #2326.
michael-simons added a commit that referenced this issue Jul 14, 2021
collection is persisted.

In case a heterogeneous is persisted via `saveAll` on a repository or
any of the templates, we do fall back to individual statements to
persist its content the same way we handle dynamic labels, versioned
entities or entities with generated ids.

The reason for this is simple: We need the exact entity to determine
labels in an inheritance hierachy, otherwise only the information given
by the lowest common denominator will be considered, effectively leading
to `saveAll` behaving different than `save`.

This fixes #2326.
@michael-simons
Copy link
Collaborator

Thanks for reporting this. This is fixed and will be released this week.

@michael-simons michael-simons added this to the 6.0.11 (2020.0.11) milestone Jul 14, 2021
@LGDOI
Copy link
Author

LGDOI commented Jul 15, 2021

You are right about the annotation. I updated the original post from @Entity to @Node for a record.
Thank you for quick resolution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug A general bug
Projects
None yet
Development

No branches or pull requests

3 participants