querydsl

How to left join unrelated entities?

删除回忆录丶 提交于 2019-12-05 03:59:50
When i try to run a query like this: QA A = QA.a; QB B = QB.b; ... from(A) .leftJoin(B).with(B.name.eq(A.nameSomething)); (A and B entities are not related) I'm always getting this error: Caused by: org.hibernate.hql.ast.QuerySyntaxException: Path expected for join! I would like to be able to left join unrelated entities using querydsl. Is it possible at all? Or the only way is to write a native Oracle query? Joining unrelated entities is not possible with Querydsl JPA. Querydsl JPA uses JPQL internally and inherit's this restriction. Assuming you're referring to JPA Criteria. innerJoin,

Spring data Querydsl in eclipse not generating query type classes

孤街浪徒 提交于 2019-12-04 17:28:29
I don't see query dsl classes generated in eclipse added below dependency and plugin in the pom.xml. Can some please review below change required for query-dsl integration in spring boot? <dependency> <groupId>com.mysema.querydsl</groupId> <artifactId>querydsl-apt</artifactId> <version>${querydsl.version}</version> <scope>provided</scope> </dependency> <dependency> <groupId>com.mysema.querydsl</groupId> <artifactId>querydsl-jpa</artifactId> <version>${querydsl.version}</version> </dependency> <!--Plugin for query-dsl --> <plugin> <groupId>com.mysema.maven</groupId> <artifactId>apt-maven-plugin

Gradle with QueryDSL 4.1.4 & Intellij

☆樱花仙子☆ 提交于 2019-12-04 15:40:57
I am trying to get my Q Classes for queryDSL 1.4.1 recongised in a Spring-Boot 1.5.2 project. The IDE is Intellij Ultimate. build.gradle buildscript { ext { springBootVersion = '1.5.2.RELEASE' } repositories { mavenCentral() } dependencies { classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}") } } plugins { id 'net.ltgt.apt' version '0.8' id 'java' } apply plugin: 'java' apply plugin: 'eclipse' apply plugin: 'org.springframework.boot' apply plugin: 'idea' version = '0.0.5-SNAPSHOT' sourceCompatibility = 1.8 ext { queryDslVersion = '4.1.4' javaGeneratedSources =

straight_join in JPA or HIBERNATE

耗尽温柔 提交于 2019-12-04 13:16:35
How to use select straight_join ... from ... in hibernate/jpa? There is no straight_join for JPQL/JPA. You will need to use it in NativeQuery. entityManager.createNativeQuery(...); It should be possible in the Hibernate 5.2.12 and MySQL version 8 using optimizer hint JOIN_FIXED_ORDER (the same effect as STRAIGHT_JOIN) More information available under the links: Jira ticket: https://hibernate.atlassian.net/browse/HHH-11906 Hibernate code change that allows this: https://github.com/hibernate/hibernate-orm/commit/72506a6eacc367297a3205f6e1fec7ccbc153799 Documentation for MySQL Optimizer hints:

Querydsl set fetch mode in a query

隐身守侯 提交于 2019-12-04 10:10:28
问题 I have a situation where a Card entity has a foreign key to a Person. public class Card implements java.io.Serializable { private String cardid; private Person person; @ManyToOne(fetch=FetchType.LAZY) @JoinColumn(name="USERID") public Person getPerson() { return this.person; } } The default fetch type for the person is LAZY. Can I specify the fetch type to EAGER within a query: QCard qCard = QCard.card; JPQLQuery query = getQuery().from(qCard); query.list(qCard); Thanks for any help. 回答1: Did

QueryDSL projections with @ManyToOne relation

余生长醉 提交于 2019-12-04 10:06:41
I'm using OpenJPA with QueryDSL, I try to avoid manipulating Tuple objects by using the bean projections features of QueryDSL. I have for example these two Entity, with a @ManyToOne relation. @Entity public class Folder { private Long id; private String name; private String path; @ManyToOne @JoinColumn(name = "FK_FILE_ID") private File file; } @Entity public class File { private Long id; private String fileName; } When I'm executing this query : List<Folder> listFolders = query.from(folder) .list(Projections.bean(Folder.class, folder.name, folder.file.fileName)); I have an error saying that

Collections in QueryDSL projections

為{幸葍}努か 提交于 2019-12-04 09:50:13
I am trying to use a projection to pull in data from an entity an some relations it has. However. The constructor on the projection takes three arguments; a set, integer and another integer. This all works fine if I don't have the set in there as an argument, but as soon as I add the set, I start getting SQL syntax query errors. Here is an example of what I'm working with... @Entity public class Resource { private Long id; private String name; private String path; @ManyToOne @JoinColumn(name = "FK_RENDITION_ID") private Rendition rendition; } @Entity public class Document { private Long id;

Is there a way to eager fetch a lazy relationship through the Predicate API in QueryDSL?

只愿长相守 提交于 2019-12-04 08:01:03
问题 I am using the QueryDslPredicateExecutor from Spring Data JPA project, and I am facing the need to eager fetch a lazy relation. I know that I can use a native JPA-QL query in the Repository interface, or even used the JPAQLQuery from Query DSL, but I was intrigued if this is even possible in order to facilitate building queries for future needs. 回答1: I had a similar problem where I had to fetch join a Collection while using Predicates and QueryDslPredicateExecutor. What I did was to create a

Spring Data Jpa最佳实践

与世无争的帅哥 提交于 2019-12-04 06:33:26
前言 Spring Data Jpa框架的目标是显著减少实现各种持久性存储的数据访问层所需的样板代码量。Spring Data Jpa存储库抽象中的中央接口是Repository。它需要领域实体类以及领域实体ID类型作为类型参数来进行管理。该接口主要用作标记接口,以捕获要使用的类型并帮助您发现扩展该接口的接口。CrudRepository、JpaRepository是更具体的数据操作抽象,一般我们在项目中使用的时候定义我们的领域接口然后继承CrudRepository或JpaRepository即可实现实现基础的CURD方法了,但是这种用法有局限性,不能处理超复杂的查询,而且稍微复杂的查询代码写起来也不是很优雅,所以下面看看怎么最优雅的解决这个问题。 扩展接口用法 /** * @author: kl @kailing.pub * @date: 2019/11/11 */ @Repository public interface SendLogRepository extends JpaRepository<SendLog,Integer> { /** * 派生的通过解析方法名称的查询 * @param templateName * @return */ List<SendLog> findSendLogByTemplateName(String templateName); /**

Spring Boot + Spring Data JPA 项目整合开发记录(持续更新)

空扰寡人 提交于 2019-12-04 05:09:25
刚换了公司,项目架构师提出新的系统架构时还是愣了一下,搭建难度较低,很容易上手,但是对Spring Data JPA的了解不够深入,所以还是有些吃力,在框架搭建初期有许多东西并没有很好的集成。 20180714-这个项目表与表之间的耦合度太低了,且不允许在实体类中进行外键对象关联,一对多、多对一、多对多的关系处理就比较复杂了,Spring Data JPA提供了好几种不同的接口调用方式,因此什么时候使用什么样的方法显得尤为重要,不同的方法编写方式也不太一样,在数据处理方面比较头疼,如果需要抽取不同表之间的数据为结果,要做联合查询且需要额外在声明一个相应的实体类来接受,不然就只能将外键表字段存储到本表中,相当费劲。 框架体系 Spring Boot + Spring Data JPA + Spring Security + Spring Security oAuth2.0 + Thymeleaf Spring Boot Spring Data JPA Spring Security Thymeleaf Vue.js Vue Element-ui Node.js 与 NPM(辅助,安装Node后,NPM会附带安装),附带webpack工具、路由等。 实体类中并没有声明 任何外键关联关系 ,因此我们查询了许多种方法来解决外键关联查询并返回结果的方法。 Spring Data JPA -