我说JPA+QueryDSL是最好的orm实现方案没人反对吧?
从开始使用jpa+QueryDSL之后所有话事的新项目和还未完成的老项目也都换成了这种方案来实现orm
因为真的很香!
6月16日17日 querydsl团队合并了QueryDSL 5 的pr,时隔9个月,QueryDSL也终于迎来了新的大版本,
本来想等等英语好的老哥翻译看看有啥新功能的,但是等不及了,配合蹩脚的英语和机翻,直接先吃!
以下来自官方github的release
QueryDSL 5.0.0.M1
此版本的 QueryDSL 以最低支持Java8为目标,进行了各种改进,为现代 Java 生态做准备。
删除了 joda-time:joda-time
、com.google.guava:guava
和 com.google.code.findbugs:jsr305
的运行时(runtime)依赖
因为QueryDSL项目大部分时间都没有得到维护,所以5.0也是大家期待已久的版本!我们将在该版本中优先解决在社区中被反复提出的历史遗留问题
非常感谢所有的贡献者牺牲了自己的休息时间做出贡献,使得这个版本成为了可能:
- @mp911de, for working on the MongoDB Document API;
- @daniel-shuy, 解耦
querydsl-sql
与joda-time:joda-time
; - @heesuk-ahn, 负责改进对Hibernate的支持和
JPASQLQuery
中的计数查询; - @harshtuna,
querydsl-collections
的NullsLast排序; - @kherrala, @ridoo and @NikitaKochkurov,
querydsl-spatial
的 JTS 和 GeoLatte 升级; - @ridoo,
HibernateDomainExporter
和JPADomainExporter
的Spatial支持; - @lpandzic, Java 15 records 的 codegen支持,一般改进迭代;
- @F43nd1r, Kotlin 代码生成, Java 11 支持, 一般改进迭代和CI;
- @jwgmeligmeyling, @Shredder121, @johnktims, @idosal and @robertandrewbain.
New features
-
#2672 - 在Java8源码层面对性能和代码做了各种提升和改进
-
#2672 - 添加了返回
Stream<T>
的Fetchable#stream()
。(笔:这个新功能还是蛮重要的)Make sure that the returned stream is always closed to free up resources, for example using try-with-resources.
It does not suffice to rely on a terminating operation on the stream for this (i.e.forEach
,collect
). -
#2324 - 移除Guava依赖项
Almost no required transitive dependencies to get started with QueryDSL.
And no more conflicts with Guava versions required by your other tools or own application. -
#2025 -
joda-time:joda-time
不再是querydsl-sql
的必要依赖项.By default, the Java 8 date/time API is used for date/time operations.
Thejoda-time:joda-time
types will still be registered automatically if they are on the classpath. -
#2215 - 通过文档API支持MongoDB 4
-
#2697 - 允许
com.querydsl.core.alias.Alias.*
依靠ECJ作为编译器,在JRE上使用。 -
#2479 - Swap out JSR305 for Jetbrains Annotations.
Because the Jetbrains Annotations, contrary to the JSR305 annotations, use a Class retention level, Jetbrains Annotations
does not have to be available at runtime and is not a transitive dependency. -
#658 - 增加了
JPAExpressions#treat
,可用于生成JPA 2.1的TreatedPath表达式。 -
#2666 - 在JPA中使用不支持的查询功能时,有更具体的错误信息。
-
#2106 -
querydsl-collections
实现了NullsLast排序. -
#2404 - Upgrade of JTS / Geolatte in
querydsl-spatial
-
#2320 -
HibernateDomainExporter
和JPADomainExporter
支持了Spatial -
#2612 - 支持 Jakarta EE 新版本的
jakarta.*
包(available through thejakarta
classifiers for Maven) -
#1376 - Expression的函数
nullif
和coalesce
返回的Expression有了具体返回类型(笔:打个比方就是Qxxx.fieldXX.nullif()函数) -
#1828 - Kotlin Codegen支持
-
#2798 - Java Record 支持(笔:高版本的东西,Java14开始出现,Java8没有哈哈)
Bugfixes
- #2579 - Count query generation in
JPASQLQuery
- #2671 - Fixed a concurrency issue in
Alias.*
.Alias.*
is now Thread safe. - #2053 - Work around issues with
AbstractJPAQuery#fetchResults
andAbstractJPAQuery#fetchCount
in a query with a having clause by using an in-memory calculation. - #2504 - Work around issues with
AbstractJPAQuery#fetchResults
andAbstractJPAQuery#fetchCount
in a query with multiple group by expressions by using an in-memory calculation. - #2663 - Fix issues with the JPA implementation of
InsertClause
. - #2706 - Fix a memory leak in
TemplateFactory
. - #2467 - Prevent
ExtendedBeanSerializer
from generatingtoString
method twice - #2326 - Use JPA indexed parameters instead of HQL’s legacy positional parameters
- #2816 - Generated JPA query with incorrect argument binding indexes
- #1413 - Incorrect parameter values with Hibernate custom types
- #1429 - Reusing of constants in JPQL generation causes issues with hibernate query caching
Breaking changes(破坏性更新)
- 最低支持Java8. 如果你使用Java7以下,请使用4.X.X版本的QueryDSL
JavaSE6SQLExceptionWrapper
and other parts regarding pre-Java 7 exception handling are removed.- 删除了为了向后兼容传统API而设置的桥接方法。这可能会导致一些破坏性的API变化。
- 删除了依赖项Guava。如果您的应用程序依赖Guava,请确保将其添加为项目的直接依赖项,而不是依赖 QueryDSL 传递它。
- In order for Guava to be removed Mysema Codegen had to be rereleased as QueryDSL Codegen Utils.
Therefore, the classes in this module moved to a different package:com.mysema.codegen
is nowcom.querydsl.codegen.utils
.
This for example affectscom.mysema.codegen.model.SimpleType
.
Although many applications won’t touch the codgen internal classes, custom APT extensions might be affected by this. - 由于移除了 Guava,任何接收
ImmutableList
作为参数的方法现在都接受任何List
。
Normal code should handle this signature just fine.
However, make sure to check any reflective uses of these parameters. - 用于
DefaultConfiguration
的querydsl.variableNameFunctionClass
属性现在应该提供java.util.function.Function
,而不是com.google.common.base.Function
。 CodeWriter#beginStaticMethod
现在采用java.util.function.Function
而不是com.google.common.base.Function
.AbstractLuceneQuery
现在采用java.util.function.Function
而不是com.google.common.base.Function
.AbstractMongodbQuery
现在采用java.util.function.Function
而不是com.google.common.base.Function
.com.querydsl.codegen.NamingFunction
,EvaluatorFunction
,DefaultVariableFunction
从继承com.google.common.base.Function
改为继承java.util.function.Function
.- 任何需要传入
javax.inject.Provider
的构造函数,现在都需要一个java.util.function.Supplier
来代替。在大多数情况下,你可以用provider::get
代替这个参数 - 这个版本继承的Hibernate主要针对Hibernate5.2。如果你需要Hibernate 4方言的特定工作方法,请使用
HQLTemplates
而不是Hibernate5Templates
。 - 删除了所有的弃用函数
joda-time:joda-time
现在是一个可选的依赖关系。如果你的应用程序也依赖了joda-time:joda-time
,请确保将其作为直接依赖关系,而不是依靠QueryDSL来引入它。com.google.code.findbugs:jsr305
is no longer a dependency. If your application currently relies on QueryDSL shipping JSR305 transitively, you should add JSR305 as a direct dependency to your project.(笔:同上,不翻译了)- MDC keys现在使用下划线
_
而不是点.
作为分隔符:querydsl.query现在是querydsl_query,querydsl.parameters是querydsl_parameters。 - Removal of
PolyHedralSurface
inquerydsl-spatial
andquerydsl-sql-spatial
due to the upgrade ofgeolatte-geom
. com.querydsl.apt.Extension
moved tocom.querydsl.codegen
and now resides in thequerydsl-codegen
module.com.querydsl.apt.SpatialSupport
moved tocom.querydsl.spatial.apt.SpatialSupport
and now resides in thequerydsl-spatial
module.com.querydsl.sql.codegen.SpatialSupport
moved tocom.querydsl.sql.spatial.SpatialSupport
and now resides in thequerydsl-sql-spatial
module.(笔:同上,一些模块上的变化)SQLServerGeometryReader
inquerydsl-sql-spatial
is removed in favour oforg.geolatte.geom.codec.db.sqlserver.*
.PGgeometryConverter
inquerydsl-sql-spatial
is removed in favour oforg.geolatte.geom.codec.Wkt
.JGeometryConverter
inquerydsl-sql-spatial
is removed in favour oforg.geolatte.geom.codec.db.oracle.*
.(笔:同上,querydsl-sql-spatial的一些XX代替了一些XX)- 删除了
querysql-jpa-codegen
中的HibernateDomainExporter
。HibernateDomainExporter
只支持Hibernate 4,而QueryDSL不再积极支持Hibernate。相反,使用Hibernate和JPADomainExporter。 ComparableExpression#coalesce
(和其子类型)不再返回mutable的Coalesce Expression
,而是返回一个具体类型(typed)的Expression。
如果您需要Coalesce builder
,请改用new Coalesce<T>().add(expression)
。getConstantToNamedLabel
、getConstantToNumberedLabel
和getConstantToAllLabels
是在SerializerBase
和JPQLSerializer
中临时引入的,用于最终取代 QueryDSL 4.3.0的getConstantToLabel
。
现在getConstantToLabel
已被删除,转而使用getConstants
。
Deprecations (弃用)
AbstractJPAQuery#fetchResults
和AbstractJPAQuery#fetchCount
现在已经不再适用于有多个group by
表达式或有子句的查询,因为这些情况不能由纯JPA支持,而是在内存中来计算的。
如果不需要计算结果的总数,我们建议使用AbstractJPAQuery#fetch
来代替。
如果你想要一个即便复杂但是可靠的方法来计算分页结果的数量,我们建议使用Blaze-Persistence QueryDSL integration。
BlazeJPAQuery
正确地实现了fetchResults
和fetchCount
,甚至还带有page
方法。
getConstantToLabel
which was deprecated in QueryDSL 4.3.0 is no longer deprecated.(笔:上面破坏性更新说了)
Dependency updates (依赖升级)
cglib:cglib
to 3.3.0 for Java 8+ supportorg.eclipse.jdt.core.compiler:ecj
to 4.6.1 for Java 8+ supportjoda-time:joda-time
to 2.10.10 for better interoperability with other frameworks that use more recent versions than QueryDSL.
joda-time:joda-time
is also no longer a required dependency and as such is no longer provided transitively to your application.
If your application relies onjoda-time:joda-time
being available, make sure to add the dependency to your project.org.geolatte:geolatte-geom
to 1.8.1 for better interopability with Hibernate Spatial.
querydsl-spatial
is still backwards compatible with older versions of Geolatte, however,querydsl-sql-spatial
is not and requires 1.4.0 or newer.com.vividsolutions:jts
toorg.locationtech:jts
for better interopability with Hibernate Spatial.
com.vividsolutions:jts
is still supported forquerydsl-spatial
if an older version oforg.geolatte:geolatte-geom
is provided.- DataNucleus 5.2.x for Java 8+ support
- JDO now uses
org.datanucleus:javax.jdo
instead ofjavax.jdo:jdo-api
- JDO now uses
com.google.guava:guava
is no longer a dependency of QueryDSL and as such is no longer provided transitively to your application.
If your application relies oncom.google.guava:guava
being available, make sure to add the dependency to your project.com.google.code.findbugs:jsr305
is no longer a dependency of QueryDSL and as such is no longer provided transitively to your application.
If your application relies oncom.google.code.findbugs:jsr305
being available, make sure to add the dependency to your project.
以上
有很多地方可能翻译有错误,希望大家指出🖖
有部分翻译,比如bugfix和依赖升级的地方我没有做翻译,因为翻译起来难度很大(我是废物!),有遇到bug的小伙伴可能也不需要我的翻译,直接就看到了,所以没有翻译👐
翻译的过程虽然比较消耗精力,但是可以很好地了解一个项目的更新内容和方向,还是很快乐的💖