我目前正在开发一个使用queryDSL和hibernate的项目,其中需要一个select文字.按照这里发布的示例我有:
createQuery().
from(path()).
where(specification().getPredicate()).
list(
ConstructorExpression.create(Foo.class, Expressions.constant(BigDecimal.ONE)));
Run Code Online (Sandbox Code Playgroud)
其中Foo类有一个接受BigDecimal的构造函数.在测试中运行时,我得到了
org.hibernate.QueryException: Parameters are only supported in SELECT clauses when used as part of a INSERT INTO DML statement
at org.hibernate.hql.internal.ast.tree.SelectClause.initializeExplicitSelectClause(SelectClause.java:146)
Run Code Online (Sandbox Code Playgroud)
将此更改为:
createQuery()
.from(path()).
where(specification().getPredicate())
.list(
ConstructorExpression.create(Foo.class, NumberTemplate.create(BigDecimal.class, "1.0")));
Run Code Online (Sandbox Code Playgroud)
产生不同的堆栈跟踪:
java.lang.IllegalArgumentException: argument type mismatch
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
at com.mysema.query.types.ConstructorExpression.newInstance(ConstructorExpression.java:133)
at com.mysema.query.jpa.FactoryExpressionTransformer.transformTuple(FactoryExpressionTransformer.java:50)
Run Code Online (Sandbox Code Playgroud)
我尝试将Foo类构造函数更改为接受Integer并将查询修改为使用Integer以便进行测试,它确实生成了正确的查询:
createQuery()
.from(path()).
where(specification().getPredicate())
.list(ConstructorExpression.create(LevelBoundary.class, NumberTemplate.create(Integer.class, "1")));
Run Code Online (Sandbox Code Playgroud)
使用NumberTemplate选择BigDecimal文字的正确方法是什么?NumberTemplate docs指定T扩展Number和Comparable但在非Integer类型上失败.如何在querydsl中正确选择常量/文字?
我被困在尝试查询(QueryDSL)工作,这给了我一个不同类别的计数.例如,我想要实现的目标:
categoryA -> 10 entries
categoryB -> 20 entries
Run Code Online (Sandbox Code Playgroud)
这是我到目前为止:
query().from(application)
.transform(groupBy(application.category).as(list(application)));
Run Code Online (Sandbox Code Playgroud)
但是,这给了我每个类别所有整个条目的列表,我只想得到这个.
我试着乱搞count()但没有运气.
有人知道怎么做吗?
Spring Boot 1.3.2.RELEASE
QueryDSL 3.7.2
QueryDSL Maven插件1.1.3
Hibernate 4.3.11.Final
目前,我有一个Spring Boot应用程序,它使用Spring Data JPA(由Hibernate支持)具有一些基本的CRUD功能,并使用Spring Data Envers进行审计.我还有以下端点来检索实体列表:
现在,我想使用Spring通过@QuerydslPredicate注释提供的新QueryDSL支持.这适用于大多数字段或子实体,但它似乎不适用于子实体的集合.文档,博客文章等似乎不包括这种情况 - 我能找到的唯一信息是它支持简单集合的"in"(即字符串的集合等).
所以,我的实体设置如下:
Person.java
@Data
@Entity
@Audited
public class Person {
@Id
private long id;
private String name;
private List<Pet> pets = new ArrayList<>();
}
Run Code Online (Sandbox Code Playgroud)
Pet.java
@Data
@Entity
@Audited
public class Pet {
@Id
private long id;
private int age;
}
Run Code Online (Sandbox Code Playgroud)
我使用the生成我的Q类com.mysema.maven:apt-maven-plugin,它QPerson使用以下字段生成我:
public final ListPath<com.test.Pet, com.test.QPet> pets = …Run Code Online (Sandbox Code Playgroud) 我们正在使用Spring Boot,Hibernate,Query DSL和Maven与Java 1.8的设置
最近,我使用下面列出的配置将Query DSL添加到项目中.为了使它工作,我必须在eclipse项目设置中配置Java编译器以允许注释处理,并将查询DSL .jar文件添加到eclipse注释工厂路径.
此设置按预期工作.它生成了自定义Q类,我可以在我的代码中使用它们.当现在mvn clean install在命令行上运行时,我的代码中的每个类都会抛出错误cannot find symbol,因为缺少该类.还有什么我需要配置 - 类似于.jareclipse设置中的文件 - 以使构建过程工作?
编辑:这个问题是不是重复这个问题,因为我没有问为什么这个错误(无法找到一个符号)发生,而是如何QueryDSL配置也命令行上工作.
EDIT2:我现在尝试集成build-helper-maven-plugin使用多个源路径作为输入.这也没有帮助.我还尝试将文件生成到一个src文件夹中.它也没有帮助.
当我第一次在eclipse中编译库时,它mvn compile会在命令行中运行,但mvn clean compile仍然会失败,因为它只是再次使用eclipse的编译文件.apt-maven-plugin被执行,可以在构建过程失败之前看到:
[INFO] --- apt-maven-plugin:1.1.3:process (default) @ project1 ---
[INFO]
[INFO] --- build-helper-maven-plugin:1.9.1:add-source (add-source) @ project1 ---
[INFO] Source directory: C:\Users\user1\git\project1\src\main\generated added.
[INFO]
[INFO] --- maven-processor-plugin:2.2.4:process (process) @ project1 ---
[ERROR] diagnostic: [...]
Run Code Online (Sandbox Code Playgroud)
编辑3:当我删除每个引用Q类的import语句时,构建过程会经历(显然).然而,值得注意的是,Q在这种情况下,类被正确编译.它们 …
一年多以来,我们已经提交了QueryDSL。 https://github.com/querydsl/querydsl 我们应该认为这个项目已经死了还是正在搬到一个新的小组?我想老团队已经没有维护它的计划了。新的JDK每6个月到货,我想这个项目将比我们预期的要早过时。有什么新闻或兼容的替代品吗?
在通过JPA,QueryDSL时,他们都包含了类型安全查询的概念.但究竟是什么呢?根据博客/文章,我想JPA/QueryDSL的一个功能是在进行查询时验证它们的参数类型.并且查询的任何错误都会在编译时而不是运行时出现.我对吗?它只是为了这个还是我错过了什么?
我在我的项目中使用了 querydsl、hibernate 和 spring data jpa。我编写了这个本机查询并且工作正常。但是我如何在 Querydsl 中编写这个查询。
List<OpenChart> openChartList = (List<OpenChart>) getEntityManager()
.createNativeQuery( "select * from (select * from open_chart order by id desc ) open_chart where user_id="+userId+" group by patient_chart_id order by id",OpenChart.class).getResultList();
Run Code Online (Sandbox Code Playgroud) 是否有可能在spring-data存储库中有两个方法 - 一个没有锁定T findOne(Predicate p);在一起但有锁定@Lock(LockModeType.PESSIMISTIC_WRITE) T findOne(Predicate p);?
我希望有类似的东西
public interface TransactionRepository extends JpaRepository<Transaction, String>,
QueryDslPredicateExecutor<Transaction> {
@Lock(LockModeType.PESSIMISTIC_WRITE)
@AliasFor("findOne")
Transaction findOne_withLock(Predicate p);
}
Run Code Online (Sandbox Code Playgroud) 使用mysemma的querydsl显示自动生成的sql查询的任何最佳方式,以便可以轻松查看这些sql查询,并且在使用querydsl时调试sql查询变得容易。
例如: from(qCustomer).where(qCustomer.custId.eq("1"));
我需要知道幕后生成的 sql 并希望记录日志以便我可以轻松调试我的应用程序。
我尝试在 Spring Boot 中将 Query DSL 与 MongoDB 结合使用,但出现错误。该应用程序无需使用 MongoDB 的 Query DSL 库即可成功运行。我想使用这个库,因为我想使用更复杂的查询。代码应该可以工作,我认为某处有一个小错误。
问题是当我单击 Maven 包时,我收到这些错误,不幸的是我无法在此处发布所有输出:
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'hotelController' defined in file [C:\Users\dgs\IdeaProjects\springboot-mongodb\target\classes\com\dgs\springbootmongodb\controller\HotelController.class]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'hotelRepository': Invocation of init method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.data.mongodb.repository.support.QuerydslMongoPredicateExecutor]: Constructor threw exception; nested exception is java.lang.IllegalArgumentException: Did not find a query class com.dgs.springbootmongodb.models.QHotel for domain class com.dgs.springbootmongodb.models.Hotel!
Caused by: org.springframework.beans.factory.BeanCreationException: Error …Run Code Online (Sandbox Code Playgroud)