querydsl

How to implement custom repository based on JpaRepository in spring?

拈花ヽ惹草 提交于 2019-12-25 03:29:07
问题 Context: I used queryDSL in API controller which binds query to the database get. Currently, I have two tables with OneToOne relationship, and we can call them Table A and Table B. If there are 3 rows in A and 2 rows in B, when I get list A with some conditions, and the queryDSL will generate query SQL like A CROSS JOIN B WHERE A.id=B.a_id , but it will miss one item in A. Thus, I am going to implement custom repository to support change join type when generating the SQL statement. The

How do I configure (XML) QueryDSL to be used with Spring Data and Spring MVC?

跟風遠走 提交于 2019-12-24 13:07:27
问题 Quick reference for those looking to configure Spring MVC, Spring Data, and QueryDSL using XML config. 回答1: In pom.xml : <properties> <querydsl.version>3.6.7</querydsl.version> </properties> <dependencies> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-log4j12</artifactId> <version>1.6.1</version> <scope>compile</scope> </dependency> <dependency> <groupId>org.springframework.data</groupId> <artifactId>spring-data-jpa</artifactId> <version>1.9.0.RELEASE</version> </dependency>

Classes generated by QueryDSL/APT and static imports

[亡魂溺海] 提交于 2019-12-24 11:54:08
问题 Apparently I can't use classes generated with APT in unit tests that use static imports. (Maven sample project can be downloaded here) If the following sample class import com.mysema.query.jpa.impl.JPAQuery; public class UserStore { public void something() { new JPAQuery(null).from(QUser.user).list(QUser.user.login); } } is changed to import static something.QUser.user; import com.mysema.query.jpa.impl.JPAQuery; public class UserStore { public void something() { new JPAQuery(null).from(user)

Kotlin-Kapt Annotation Processor not working with maven

江枫思渺然 提交于 2019-12-24 07:46:44
问题 I want to generate jpa querydsl files from kotlin entity classes. There is a very good examples online of how to generate the dsl files using gradle https://github.com/JetBrains/kotlin-examples/blob/master/gradle/kotlin-querydsl/build.gradle. However I have tried to implement this in maven and have had no luck. My current pom is below. Does anybody know what the issue might be? Thanks in advance. <project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM

Left join on unrelated tables in Query DSL and JPA

风格不统一 提交于 2019-12-24 03:39:39
问题 I have two unrelated tables, each one with field email. I need a query which introduces column taken from second table if emails match or will be null if no match is found. In SQL this is easy: SELECT tableA.id, tableA.email, tableB.name FROM tableA LEFT JOIN tableB ON tableA.email=tableB.email ORDER BY tableB.name Unfortunately JPA doesn't allow joins over unrelated entities so I converted it to: SELECT tableA.id, tableA.email, (SELECT tableB.name FROM tableB WHERE tableB.email=tableA.email)

QueryDSL: generate Predicate from PathBuilder

有些话、适合烂在心里 提交于 2019-12-24 03:12:58
问题 How to replace the following method that uses the generated Q* class and java reflexion with a PathBuilder? // member vars: T operand; // can be a BigDecimal or a String String tableName; String fieldName; String methodName; public Predicate asPredicate() { Class<?> tableClazz = Class.forName("foo.bar.database.model.Q"+ WordUtils.capitalize(tableName)); Object tableObj = tableClazz.getConstructor(String.class).newInstance(tableName +"1000"); Field colField = tableClazz.getDeclaredField

W.r.t. Pass options to JPAAnnotationProcessor from Gradle

拟墨画扇 提交于 2019-12-24 02:07:25
问题 I am using Gradle version 2.14, I have made changes in build.gradle to exclude packages from JPAAnnotationProcessor as mentioned in question. My build.gradle configuration for same as follows: configurations { querydslapt } dependencies{ compile group: 'com.querydsl', name: 'querydsl-core', version: '4.1.4' compile group: 'com.querydsl', name: 'querydsl-apt', version: '4.1.4' compile group: 'com.querydsl', name: 'querydsl-jpa', version: '4.1.4' } task generateQueryDSL(type: JavaCompile, group

@Query not working with QueryDSL predicate

纵饮孤独 提交于 2019-12-23 23:14:55
问题 I'm trying to use @Query over QueryDSL 's Overrided method, but when i'm doing that, it is ignoring my predicate which i'm providing e.g. http://localhost:8080/orders?state=Texas The reason i need @Query is to apply security based on authentication principal e.g. @Query("select o from Orders o where ?#{principal.username} = o.username") Complete code of repository: public interface OrderRepository extends JpaRepository<Order, Integer>, QuerydslPredicateExecutor<Order>{ @Override @Query(

Can't get QueryDsl / APT to generate Q classes

让人想犯罪 __ 提交于 2019-12-23 23:07:46
问题 I'm trying to use QueryDsl in a new Spring project. I'm new to QueryDsl, and pretty new to maven and Spring, so I may be missing something fairly basic, but I can't get QueryDsl / maven-apt-plugin to generate my Q classes. The Querydsl reference makes sound so easy; I think I did exactly what it said: I configured pom.xml with: <plugin> <groupId>com.mysema.maven</groupId> <artifactId>maven-apt-plugin</artifactId> <version>1.0.3</version> <executions> <execution> <goals> <goal>process</goal> <

QueryDSL to get any entities in a collection of another entity

穿精又带淫゛_ 提交于 2019-12-23 17:27:55
问题 I'm using JPA with Hibernate and QueryDSL (v.4.0.5). I have this entity: package com.test.model.entity; @Entity public class Article { @Id private Long id; @ManyToMany(fetch = LAZY, cascade = DETACH) private Set<Tag> tags; } How can I find all the articles matching a given set of Tag s? I think I should start as follows: public BooleanExpression hasTag(Set<Tag> tags){ final QArticle article = QArticle.article; return article.tags.any().eqAny(ce); } where ce should be a CollectionExpression .