neo4j / neo4j-ogm

Java Object-Graph Mapping Library for Neo4j
https://neo4j.com/docs/ogm-manual/
Apache License 2.0
328 stars 163 forks source link

RelationshipEntity repository breaks when i update Spring boot version #792

Closed Velicko91 closed 4 years ago

Velicko91 commented 4 years ago

Hi, I was working with @RelationshipEntity and repository for that bean. It worked fine with spring boot 2.2.0 until i tried to update spring boot to newest 2.2.6 version. After update, query always returned null. These are my entity beans:

@Getter
@Setter
public abstract class AbstractEntity {
    @Id
    @GeneratedValue
    private Long id;
}
@Getter
@Setter
@NodeEntity
@RelationshipEntity(type = "MENTION")
public class RelationshipNeo4j extends AbstractEntity {

    @Property
    protected String type;

    @Property
    protected LocalDate date;

    @StartNode
    protected Entity start;

    @EndNode
    protected Entity end;
    }
@Getter
@Setter
@NodeEntity
public class Entity extends AbstractEntity {

    protected String name;

    @Index(unique = true)
    protected String  uuid;

    protected String wikiUrl;

    protected String  description;

    @Relationship(type="MENTION")
     protected List<RelationshipNeo4j> relationships;

}

and repository:

@Repository
public interface RelationshipRepository extends Neo4jRepository<RelationshipNeo4j, Long> {

    @Query("MATCH (e:Entity {uuid:{entity1uuid}}), (e2:Entity{uuid:{entity2uuid}}) CREATE (e)-[r:MENTION{uuid:{relationshipUuid},type:{type},date:{date}}]->(e2) RETURN e,e2,r")
    RelationshipNeo4j createRelationshipBetweenExistingEntities(String  entity1uuid, String  entity2uuid, String  relationshipUuid, String  type, String date);
}

So i started to increment spring boot version to check when it will break. It works for Spring boot 2.2.0 and 2.2.1. Then it breaks with 2.2.2 and does't work for all higher versions. Spring boot 2.2.1 goes with neo4j-ogm:3.2.2 Sprinb boot 2.2.2 goes with neo4j-ogm:3.2.3

meistermeier commented 4 years ago

Could you compare your code with the one I created here: https://github.com/meistermeier/neo4j-issues-examples/tree/master/neo4j-ogm-792 It should be the same besides the Lombok annotations and it is working for Spring Boot 2.2.1 and Spring Boot 2.2.2

Velicko91 commented 4 years ago

Hi, I compared and in my code there is sessionFactory bean and configuration initialized in java @Configuration. I've updated your code so that it is more similar to mine, but i can't push to your repo. Only difference that i see now is required usage of @Param in your code. I've also tried to update my with @param and to remove sessionFactory and configuration Beans, so that spring initialize it, but i am getting same output, returns null but creates relationship in database.

Added Actually when i try your simple configuration embedded database is started.

meistermeier commented 4 years ago

I am happy to see a diff as an PR on my repo. Additionally, no embedded instances gets started there. How do you come to this conclusion?

Velicko91 commented 4 years ago

when I push new branch i'm getting: remote: Permission to meistermeier/neo4j-issues-examples.git denied to Velicko91. fatal: unable to access 'https://github.com/meistermeier/neo4j-issues-examples.git/': The requested URL returned error: 403

These are my logs when i start Spring boot:

2020-05-07 15:33:27.421  INFO 12220 --- [    Test worker] s.l.w.r.PageRestControllerTest           : Starting PageRestControllerTest on DESKTOP-P1AED7V with PID 12220 (started by Velicko in C:\Users\Velicko\Desktop\uros\java\upwork\neo4j\Wumu\wumu-server)
2020-05-07 15:33:27.436  INFO 12220 --- [    Test worker] s.l.w.r.PageRestControllerTest           : No active profile set, falling back to default profiles: default
2020-05-07 15:33:28.598  INFO 12220 --- [    Test worker] .s.d.r.c.RepositoryConfigurationDelegate : Multiple Spring Data modules found, entering strict repository configuration mode!
2020-05-07 15:33:28.601  INFO 12220 --- [    Test worker] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFAULT mode.
2020-05-07 15:33:28.721  INFO 12220 --- [    Test worker] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 108ms. Found 4 JPA repository interfaces.
2020-05-07 15:33:28.726  INFO 12220 --- [    Test worker] .s.d.r.c.RepositoryConfigurationDelegate : Multiple Spring Data modules found, entering strict repository configuration mode!
2020-05-07 15:33:28.727  INFO 12220 --- [    Test worker] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data Neo4j repositories in DEFAULT mode.
2020-05-07 15:33:28.742  INFO 12220 --- [    Test worker] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 12ms. Found 2 Neo4j repository interfaces.
2020-05-07 15:33:28.751  INFO 12220 --- [    Test worker] .s.d.r.c.RepositoryConfigurationDelegate : Multiple Spring Data modules found, entering strict repository configuration mode!
2020-05-07 15:33:28.751  INFO 12220 --- [    Test worker] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data Neo4j repositories in DEFAULT mode.
2020-05-07 15:33:28.759  INFO 12220 --- [    Test worker] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 7ms. Found 2 Neo4j repository interfaces.
2020-05-07 15:33:29.544  INFO 12220 --- [    Test worker] trationDelegate$BeanPostProcessorChecker : Bean 'application' of type [software.leader.wumu.boot.Application$$EnhancerBySpringCGLIB$$83b778ce] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2020-05-07 15:33:29.694  INFO 12220 --- [    Test worker] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration' of type [org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2020-05-07 15:33:30.191  INFO 12220 --- [    Test worker] o.s.b.w.e.t.TomcatWebServer              : Tomcat initialized with port(s): 0 (http)
2020-05-07 15:33:30.209  INFO 12220 --- [    Test worker] o.a.c.c.StandardService                  : Starting service [Tomcat]
2020-05-07 15:33:30.211  INFO 12220 --- [    Test worker] o.a.c.c.StandardEngine                   : Starting Servlet engine: [Apache Tomcat/9.0.29]
2020-05-07 15:33:30.423  INFO 12220 --- [    Test worker] o.a.c.c.C.[.[.[/]                        : Initializing Spring embedded WebApplicationContext
2020-05-07 15:33:30.423  INFO 12220 --- [    Test worker] o.s.w.c.ContextLoader                    : Root WebApplicationContext: initialization completed in 2951 ms
2020-05-07 15:33:30.934  WARN 12220 --- [    Test worker] o.n.o.d.e.d.EmbeddedDriver               : Creating temporary file store: file:/C:/Users/Velicko/AppData/Local/Temp/neo4jTmpEmbedded.db7835556935401033106/database/
2020-05-07 15:33:34.757  INFO 12220 --- [    Test worker] o.n.o.m.DomainInfo                       : Starting Post-processing phase
2020-05-07 15:33:34.757  INFO 12220 --- [    Test worker] o.n.o.m.DomainInfo                       : Building byLabel lookup maps
2020-05-07 15:33:34.758  INFO 12220 --- [    Test worker] o.n.o.m.DomainInfo                       : Building interface class map for 39 classes
2020-05-07 15:33:34.788  INFO 12220 --- [    Test worker] o.n.o.m.DomainInfo                       : Post-processing complete

As I understand embedded database is being started. This is the log when i removed @bean for configuration and SessionFactory and changed application.property to spring.datasource.url=jdbc:mysql://localhost:3306 spring.datasource.username=neo4j spring.datasource.password=secret.

meistermeier commented 4 years ago

Git(Hub)'s behaviour is correct: You cannot simply push to branches/repositories of others but instead create a fork, make your changes and submit a pull request for the target (mine) repository. https://help.github.com/en/github/collaborating-with-issues-and-pull-requests/creating-a-pull-request

For the problem itself:

spring.datasource.url=jdbc:mysql://localhost:3306
spring.datasource.username=neo4j
spring.datasource.password=secret.

Those are JDBC related properties and not Neo4j's ones. In the first line you say you want to connect to a MySql database.

By not setting the spring.data.neo4j.[uri|user|password], SDN will go into some kind of fallback mode and spin up an embedded instance by default.

Velicko91 commented 4 years ago

Ok, I created pull request.

Srry i copied wrong connection properties, i have both. This is my whole property file.

spring.datasource.url=jdbc:mysql://localhost:3306
spring.datasource.username=root
spring.datasource.password=root
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver

spring.data.neo4j.username=root
spring.data.neo4j.password=root
spring.data.neo4j.uri=bolt://localhost:7687
meistermeier commented 4 years ago

Just had a look at your code. Basically it still works for me with your setup.

Using the spring-boot-starter-data-neo4j and application.properties as in your comment will create the correct beans for you without manual instantiation. (But yes, this works) Also you are somehow violating the spring-boot contract that the application.properties are reserved for spring-boot related configuration in your PR by putting in the OGM properties and providing it to the configuration.

michael-simons commented 4 years ago

Closing this as there was no other feedback. Feel free to reopen this again.