QueryDSL bindings for Spring Data JPA with Neo4j



我们有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 提供的类似无知案例等功能。

谁能知道是否有任何库可以用来绑定 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 Data Neo4j不支持QueryDSL。

支持的存储库功能可以在此页面上的表中检查。

您会注意到不支持 QueryDslPredicateExecutor。

根据Gerrit Meier的说法,没有计划在不久的将来实施它。

最新更新