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

Repository does not save nested entities starting from third level [DATAJDBC-597] #819

Closed
spring-projects-issues opened this issue Sep 4, 2020 · 1 comment
Assignees
Labels
in: repository status: declined type: bug

Comments

@spring-projects-issues
Copy link

@spring-projects-issues spring-projects-issues commented Sep 4, 2020

Alexander Birchenko opened DATAJDBC-597 and commented

I'm tying to persist a tree-like entity with structure like this:

CREATE TABLE `task` (
    `id` INT(11) NOT NULL AUTO_INCREMENT,
    `parent_id` INT(11) NULL DEFAULT NULL,
    PRIMARY KEY (`id`) USING BTREE
)
COLLATE='utf8_general_ci'
ENGINE=InnoDB;

@Data
@Table
public class Task {
    @Id
    private Integer id;
    
    @MappedCollection(idColumn = "parent_id")
    private Set<Task> subItems;
}

public interface TaskRepository extends org.springframework.data.repository.CrudRepository<Task, Integer> {}

Initialize and save entity:

Task task = new Task();
Task task2= new Task();
Task task3= new Task();

task.setSubItems(Set.of(task2));
task2.setSubItems(Set.of(task3));

taskRepository.save(task);

Expected result: task3, task2, tast - persisted
Actual result: task2, task - persisted. task3 - ignored


Affects: 2.0.3 (Neumann SR3)

1 votes, 2 watchers

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented Dec 21, 2020

Jens Schauder commented

Since Task is an aggregate, every reference to a different Task should be by id not by a Java reference, since it is a reference across aggregate boundaries.

See https://spring.io/blog/2018/09/24/spring-data-jdbc-references-and-aggregates

@spring-projects-issues spring-projects-issues added type: bug status: declined in: repository labels Dec 31, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: repository status: declined type: bug
Projects
None yet
Development

No branches or pull requests

2 participants