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

Regression on save relationships 7.1.0-M2 -> 7.1.0 #2736

Closed
bonelli opened this issue Jun 9, 2023 · 3 comments
Closed

Regression on save relationships 7.1.0-M2 -> 7.1.0 #2736

bonelli opened this issue Jun 9, 2023 · 3 comments
Labels
status: waiting-for-triage An issue we've not yet triaged

Comments

@bonelli
Copy link

bonelli commented Jun 9, 2023

Hello everyone, I think we are seeing a regression on saving relationships.

Here an example that works in 7.1.0-M2 and doesn't work in 7.1.0:

@Getter
@Setter
@RequiredArgsConstructor
public class Player {

    @Id
    private String id;

    @Version
    private Long version;

    private List<TeamMembership> teamMemberships;

    private List<ZonedDateTime> birthDates;
}
@Getter
@Setter
@RequiredArgsConstructor
public class Team {

    @Id
    private String id;

    @Version
    private Long version;

    @Relationship(type = "TEAM_MEMBERSHIPS", direction = Direction.INCOMING)
    private List<PlayerMembership> members;
}
@RelationshipProperties
@Data
@AllArgsConstructor
public class PlayerMembership {

    @RelationshipId
    private Long id;

    @TargetNode
    private final Player player;

    ZonedDateTime start;

    ZonedDateTime end;
}
@RelationshipProperties
@Data
@AllArgsConstructor
public class TeamMembership {
    @RelationshipId
    private Long id;

    @TargetNode
    private final Team team;

    ZonedDateTime start;

    ZonedDateTime end;
}

And here the test code that reveals the error:

@Test
    public void testWrite_and_get() {
        System.out.println("testWrite_and_get");

        Player p1 = new Player();
        Team t1 = new Team();
        p1.setId("p1");
        t1.setId("t1");
        p1.setTeamMemberships(Arrays.asList(new TeamMembership(null, t1, ZonedDateTime.now(), null)));

        playersRepository.save(p1);

        Optional<Player> optPlayer = playersRepository.findById("p1");

        var actualPlayer = Assertions.assertThat(optPlayer)
                .isNotEmpty()
                .get();

        actualPlayer.extracting("id").asString()
                .isEqualTo("p1");
        actualPlayer.extracting("teamMemberships").asList()
                .hasSize(1); // <---- this fails because teamMembership is empty on database

        System.out.println("testWrite_and_get - done");
    }
@meistermeier
Copy link
Collaborator

Thanks for reporting this. This has been fixed in #2728

You can already have it working, if you define

@Configuration
public class SomeConfigurationClass {
  /** other configuration things **/
  @Bean
  public Configuration cypherDslConfiguration() {
	return Configuration.newConfig().withDialect(Dialect.NEO4J_5).build();
  }
}

in your configuration. Besides making SDN more flexible with the default Cypher-DSL dialect and Neo4j 5, this is also the advice we added to the (upcoming) documentation.
Thanks again for reporting this. I am closing this now and if there is anything else related, feel free to just re-open this issue.

@bonelli
Copy link
Author

bonelli commented Jun 12, 2023

Really glad this matter was already taken care of!

I'm wondering if you'd consider another name for org.neo4j.cypherdsl.core.renderer.Configuration, since it is almost always used in conjunction with Spring's @configuration
Not that important anyway.

@meistermeier
Copy link
Collaborator

Cypher-DSL has nothing to do with Spring (or even Spring Data Neo4j) in first place. It is an independent library that gets used in SDN and has its own set of classes to be used within every Java application.
I can see that the full qualified name to avoid import conflicts is not ideal, but this breaking change within the Cypher-DSL would in the end just be cosmetic. (Also it only occurs if people are using the custom config classes and not throw it directly in their SpringBootApplication)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: waiting-for-triage An issue we've not yet triaged
Projects
None yet
Development

No branches or pull requests

3 participants