带有Neo4j的Spring Data JPA的QueryDSL绑定

问题描述 投票:1回答:1

我们具有Spring Data JPA的功能,我们正在使用像这样的querydsl

这是我的实体:

@Entity
@RestResource(path = "car", rel = "car")
@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
@EqualsAndHashCode(callSuper = false)   
@JsonInclude(JsonInclude.Include.NON_NULL)
public class CarEntity extends VehicleEntity {

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long inventoryId;

    @Column(length = 50)
    private String make;

    @Column(length = 50)
    private String model;

    @Column(length = 500)
    private String vin;

    @Column(length = 500)
    private String type;
}

这是我的存储库:

@RepositoryRestResource(path = "car")
@CrossOrigin(origins = "*")
public interface CarEntityRepository extends PagingAndSortingRepository<CarEntity, Long>,
        QueryDslPredicateExecutor<CarEntity>, QuerydslBinderCustomizer<QCarEntity> {

    @Override
    default public void customize(QuerydslBindings bindings, QCarEntity root) {
       bindings.bind(String.class).first(
                (StringPath path, String value) -> path.likeIgnoreCase(value));
    }}  

使用以上代码,我能够实现QueryDSL功能并基于实体中的任何字段来查询实体。

现在,当我们从sql服务器迁移到Neo4j时,这是我的实体

@NodeEntity
@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
@EqualsAndHashCode(callSuper = true)
@JsonIgnoreProperties(ignoreUnknown = true)
public class CarEntity extends VehicleEntity {
@Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long inventoryId;

    @Column(length = 50)
    private String make;

    @Column(length = 50)
    private String model;

    @Column(length = 500)
    private String vin;

    @Column(length = 500)
    private String type;
}

这是我的相同存储库

@CrossOrigin("*")
public interface CarRepository extends 
           Neo4jRepository<CarEntity,Long> {} 

这些是我的Neo4j应用程序的一些版本和属性

springBootVersion = '2.0.4.RELEASE'
dependencies {

    // Neo4j
    compile ('org.neo4j:neo4j:3.4.9')
    compile ('org.neo4j.driver:neo4j-java-driver:1.7.2')
    compile('org.springframework.boot:spring-boot-starter-data-neo4j')
    compile ('org.hibernate.ogm:hibernate-ogm-neo4j:5.4.1.Final')

    // Spring
    compile('org.springframework.boot:spring-boot-starter')
    compile('org.springframework.cloud:spring-cloud-starter-config')
    compile('org.springframework.boot:spring-boot-starter-data-rest')
    compile('org.springframework.boot:spring-boot-starter-actuator')
    compile('org.springframework.boot:spring-boot-starter-web')

    //lombok
    compileOnly('org.projectlombok:lombok:1.18.2')

    // Testing
    testCompile('org.springframework.boot:spring-boot-starter-test')
    testCompile('org.neo4j:neo4j-ogm-embedded-driver:3.1.11')
    testCompile('org.neo4j.test:neo4j-harness:3.4.9')

    // HTTP (Requesting token for integration tests)
    testCompile('junit:junit')
    testCompile("com.jayway.restassured:rest-assured:$restAssuredVersion")
    testCompile "org.springframework:spring-test:$springVersion"
    testCompile("com.squareup.retrofit2:retrofit:$retrofitVersion")
    testCompile("com.squareup.retrofit2:converter-jackson:$retrofitVersion")

}

构建使用Neo4J的应用程序后,它不会生成QCarEntity类,并且无法绑定以实现QueryDSL提供的likeIgnoranceCase或其他功能。

谁能知道我是否可以使用任何库来绑定Neo4j实体,以及如何在构建时生成QCarEntity类

我已经尝试过这样

public interface CarEntityRepository extends Neo4jRepository<CarEntity,Long>, PagingAndSortingRepository<CarEntity, Long>, QueryDslPredicateExecutor<CarEntity>, QuerydslBinderCustomizer<QCarEntity> {

@Override
default public void customize(QuerydslBindings bindings, QCarEntity root) {
    bindings.bind(String.class).first(
            (StringPath path, String value) -> path.likeIgnoreCase(value));
} 
}

它无法生成并且无法生成QCarEntity类,如果完全生成QCarEntity,是否有办法实现此功能? Neo4j中是否有类似的类或库?

spring spring-boot neo4j spring-data-jpa querydsl
1个回答
0
投票

Spring Data Neo4j不支持QueryDSL。可以在下一页的表中检查支持的存储库功能https://docs.spring.io/spring-data/neo4j/docs/5.2.1.RELEASE/reference/html/#neo4j-repo-intro。您会注意到不支持QueryDslPredicateExecutor

© www.soinside.com 2019 - 2024. All rights reserved.