querydsl

How to create Predicate BooleanExpression for many to many relations in QueryDSL

和自甴很熟 提交于 2019-12-13 08:12:33
问题 How can inner join be done on Many to Many relations using Predicate BooleanExpression? I have 2 entities public class A { @Id @GeneratedValue(strategy = GenerationType.AUTO) private Integer id; @ManyToMany(fetch = FetchType.LAZY, cascade = { CascadeType.DETACH, CascadeType.MERGE, CascadeType.REFRESH, CascadeType.PERSIST}) @JoinTable(name = "a_b_maps", joinColumns = @JoinColumn(name = "a_id", nullable = false,referencedColumnName = "id"), inverseJoinColumns = @JoinColumn(name = "b_id",

QueryDSL JPA Functions

北城余情 提交于 2019-12-13 03:24:06
问题 I use querydsl-jpa and querydsl-sql 4.1.4 Want run simple sql /* Formatted on 04/08/2017 9:46:39 (QP5 v5.300) */ SELECT created FROM user_info WHERE TRUNC (created) <= TO_DATE ('01.01.2016', 'dd.mm.yyyy') My method compare date protected BooleanExpression dateCompare(DateTimePath<java.util.Date> dateTimePath, Date date) { DateExpression<Date> dbDate = SQLExpressions.datetrunc(DatePart.day, Expressions.asDate(dateTimePath)); DateExpression<Date> compareDate = Expressions. asDate(date); return

How to register custom Querydsl EntityPathResolver with Spring Data MongoRepositoryFactory?

泄露秘密 提交于 2019-12-13 00:47:36
问题 I am using the Querydsl extension ( QueryDslPredicateExecutor ) to my CrudRepository . To reliably exclude the generated Q classes from my test coverage measurements, they are generated into a dedicated querydsl subpackage of the respective domain classes (annotation processor option -Aquerydsl.packageSuffix=.querydsl ). Alas, this causes a ClassNotFoundException at application start up: java.lang.IllegalArgumentException: Did not find a query class org.example.QDomain for domain class org

Filter results from QueryDSL search

余生长醉 提交于 2019-12-12 22:06:08
问题 I'm using QueryDSL as part of Spring Data Rest to search entities from our API. Is it possible to somehow filter the search API, so that by default it won't find for example Car entities that are "deactivated"? Currently I've a flag on car entity that when it's set to true, it shouldn't be exposed through our search API, and the cars that have this property set should be left out from search. https://docs.spring.io/spring-data/jpa/docs/1.9.0.RELEASE/reference/html/#core.web.type-safe 回答1: In

jUnit: No primary or default constructor found for interface com.querydsl.core.types.Predicate

拈花ヽ惹草 提交于 2019-12-12 21:29:00
问题 I have a restcontroller inside a spring-application returning a list of objects... @GetMapping @Override public ResponseEntity readAll(@QuerydslPredicate(root = Entity.class) Predicate predicate, Pageable pageable){ ... } If I run it, everything works fine. I can filter the request by pageable and predicate. But if I run the junit test, it fails... @Test public void readAllTest(){ MockMvcBuilders.standaloneSetup(*myController*) .build().perform(MockMvcRequestBuilders.get(*myUri*) .accept

QueryDSL Could not determine data type for searched case statement

徘徊边缘 提交于 2019-12-12 19:16:58
问题 I have a QueryDSL statement which gives me the exception: Caused by: org.hibernate.QueryException: Could not determine data type for searched case statement [select distinct rollout, count(bTS), sum(case when bTS.status = ?1 then ?2 else ?3 end), sum(case when (bTS.status = ?4) then ?2 else ?3 end), ((sum(case when (bTS.status = ?4) then ?2 else ?3 end) / ?5) * count(bTS)) as percentage from com.nsn.nitro.project.data.jpa.domain.RolloutAdmin rolloutAdmin, com.nsn.nitro.project.data.jpa.domain

@QuerydslPredicate throwing exception

两盒软妹~` 提交于 2019-12-12 18:40:13
问题 I'm trying to understand how to use @QuerydslPredicate but my test API fails when it is called: Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is java.lang.IllegalStateException: No primary or default constructor found for interface com.querydsl.core.types.Predicate] with root cause java.lang.NoSuchMethodException: com.querydsl.core.types.Predicate.< init >() This is the method in my Controller class:

Jpa/Hibernate query return wrong result when before it executed other query

浪子不回头ぞ 提交于 2019-12-12 13:35:31
问题 I have very strange case with jpa/hibernate. I have 4 entities , something like this entity County has Set<City> City has Set<CityRegion> CityRegion has Set<House> I have 2 queries in DAO(in 2 methods). I use QueryDsl for JPA, but it generates those 2 jpa queries. select distinct county from County county inner join fetch county.cities as city inner join fetch city.cityRegions as cityRegion inner join fetch cityRegion.houses as house where city.id = ?1 select distinct county from County

How To Select literals in QueryDSL

安稳与你 提交于 2019-12-12 10:39:26
问题 Im currently working on a project that uses queryDSL and hibernate wherein it requires a select literal. Following the examples posted here i have: createQuery(). from(path()). where(specification().getPredicate()). list( ConstructorExpression.create(Foo.class, Expressions.constant(BigDecimal.ONE))); where Foo class has a constructor which accepts a BigDecimal. When running this in test, i get org.hibernate.QueryException: Parameters are only supported in SELECT clauses when used as part of a

Spring MongoDB + QueryDSL query by @DBRef related object

吃可爱长大的小学妹 提交于 2019-12-12 09:40:00
问题 I am using spring-data-mongodb and querydsl-mongodb to perform more flexible queries. My application has users and orders. An user can have multiple orders, so my models looks like this: public class User { @Id private String id; private String username; //getters and setters } public class Order { @Id private String id; @DBRef private User user; //getters and setters } As you can see, there is an has-many relationship between users and orders. Each order is assigned to an user, and the user