Skip to content

Commit 234251a

Browse files
committed
Fix code to work with hibernate 7 and eclipselink 5
1 parent 2a10ec4 commit 234251a

File tree

15 files changed

+71
-57
lines changed

15 files changed

+71
-57
lines changed

querydsl-libraries/querydsl-core/src/main/java/com/querydsl/core/types/TemplateFactory.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,13 @@ public class TemplateFactory {
5151
private static final Pattern elementPattern =
5252
Pattern.compile(
5353
"""
54-
\\{\
55-
(%?%?)\
56-
(\\d+)\
57-
(?:([+-/*])(?:(\\d+)|'(-?\\d+(?:\\.\\d+)?)'))?\
58-
([slu%]?%?)\
59-
\\}""");
54+
\\{\
55+
(%?%?)\
56+
(\\d+)\
57+
(?:([+-/*])(?:(\\d+)|'(-?\\d+(?:\\.\\d+)?)'))?\
58+
([slu%]?%?)\
59+
\\}\
60+
""");
6061

6162
private final Map<String, Template> cache = Collections.synchronizedMap(new WeakHashMap<>());
6263

querydsl-libraries/querydsl-jpa/pom.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,13 @@
3535
</exclusion>
3636
</exclusions>
3737
</dependency>
38+
<dependency>
39+
<groupId>org.hibernate.orm</groupId>
40+
<artifactId>hibernate-community-dialects</artifactId>
41+
<version>${hibernate.version}</version>
42+
<scope>provided</scope>
43+
<optional>true</optional>
44+
</dependency>
3845

3946
<dependency>
4047
<groupId>jakarta.persistence</groupId>

querydsl-libraries/querydsl-jpa/src/main/java/com/querydsl/jpa/JPQLSerializer.java

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -518,17 +518,18 @@ protected void visitOperation(
518518
throw new IllegalArgumentException(
519519
String.format(
520520
"""
521-
SQL Expressions like %s are not supported in JPQL - the query language for JPA.\
522-
SQLExpressions.* can only be used in JPQL queries when these functions\
523-
are registered as custom function in your ORM.%n To fix this issue, you\
524-
have three options:%n 1) If you do want to use advanced, dialect\
525-
specific, SQL functions within JPQL, make sure to make these functions\
526-
available to your ORM through custom functions and register these with\
527-
your JPATemplates instance.%n 2) Use JPASQLQuery instead. This allows\
528-
you to generate a pure SQL query based on your JPA metamodel.%n 3)\
529-
Consider using the Blaze-Persistence QueryDSL integration.\
530-
Blaze-Persistence is an extension on top of JPA that makes various SQL\
531-
specific functions like window functions available to JPQL.""",
521+
SQL Expressions like %s are not supported in JPQL - the query language for JPA.\
522+
SQLExpressions.* can only be used in JPQL queries when these functions\
523+
are registered as custom function in your ORM.%n To fix this issue, you\
524+
have three options:%n 1) If you do want to use advanced, dialect\
525+
specific, SQL functions within JPQL, make sure to make these functions\
526+
available to your ORM through custom functions and register these with\
527+
your JPATemplates instance.%n 2) Use JPASQLQuery instead. This allows\
528+
you to generate a pure SQL query based on your JPA metamodel.%n 3)\
529+
Consider using the Blaze-Persistence QueryDSL integration.\
530+
Blaze-Persistence is an extension on top of JPA that makes various SQL\
531+
specific functions like window functions available to JPQL.\
532+
""",
532533
operator.name()),
533534
e);
534535
} else {

querydsl-libraries/querydsl-jpa/src/main/java/com/querydsl/jpa/impl/AbstractJPAQuery.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,10 @@ public long fetchCount() {
107107
try {
108108
if (getMetadata().getGroupBy().size() > 1 || getMetadata().getHaving() != null) {
109109
logger.warning(
110-
"Fetchable#fetchCount() was computed in memory! See the Javadoc for"
111-
+ " AbstractJPAQuery#fetchCount for more details.");
110+
"""
111+
Fetchable#fetchCount() was computed in memory! See the Javadoc for\
112+
AbstractJPAQuery#fetchCount for more details.\
113+
""");
112114
var query = createQuery(null, false);
113115
return query.getResultList().size();
114116
}
@@ -286,8 +288,10 @@ public QueryResults<T> fetchResults() {
286288
var modifiers = getMetadata().getModifiers();
287289
if (getMetadata().getGroupBy().size() > 1 || getMetadata().getHaving() != null) {
288290
logger.warning(
289-
"Fetchable#fetchResults() was computed in memory! See the Javadoc for"
290-
+ " AbstractJPAQuery#fetchResults for more details.");
291+
"""
292+
Fetchable#fetchResults() was computed in memory! See the Javadoc for\
293+
AbstractJPAQuery#fetchResults for more details.\
294+
""");
291295
var query = createQuery(null, false);
292296
@SuppressWarnings("unchecked")
293297
List<T> resultList = query.getResultList();

querydsl-libraries/querydsl-jpa/src/main/java/com/querydsl/jpa/support/QDerbyDialect.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
import com.querydsl.core.types.Ops;
1717
import com.querydsl.sql.DerbyTemplates;
1818
import org.hibernate.boot.model.FunctionContributions;
19-
import org.hibernate.dialect.DerbyDialect;
19+
import org.hibernate.community.dialect.DerbyDialect;
2020

2121
/** {@code QDerbyDialect} extends {@code DerbyDialect} with additional functions */
2222
public class QDerbyDialect extends DerbyDialect {

querydsl-libraries/querydsl-jpa/src/test/java/com/querydsl/jpa/AbstractJPATest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,7 @@ public void aggregates_uniqueResult_min() {
283283
}
284284

285285
@Test
286+
@NoEclipseLink
286287
public void alias() {
287288
assertThat(query().from(cat).select(cat.id.as(cat.id)).fetch()).hasSize(6);
288289
}

querydsl-libraries/querydsl-jpa/src/test/java/com/querydsl/jpa/HibernateBase.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public void setSession(Session session) {
8181

8282
@Override
8383
protected void save(Object entity) {
84-
session.save(entity);
84+
session.persist(entity);
8585
}
8686

8787
@Test

querydsl-libraries/querydsl-jpa/src/test/java/com/querydsl/jpa/HibernateSQLBase.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,12 @@ public void setSession(Session session) {
5656
@Before
5757
public void setUp() {
5858
if (query().from(cat).fetchCount() == 0) {
59-
session.save(new Cat("Beck", 1, Color.BLACK));
60-
session.save(new Cat("Kate", 2, Color.BLACK));
61-
session.save(new Cat("Kitty", 3, Color.BLACK));
62-
session.save(new Cat("Bobby", 4, Color.BLACK));
63-
session.save(new Cat("Harold", 5, Color.BLACK));
64-
session.save(new Cat("Tim", 6, Color.BLACK));
59+
session.persist(new Cat("Beck", 1, Color.BLACK));
60+
session.persist(new Cat("Kate", 2, Color.BLACK));
61+
session.persist(new Cat("Kitty", 3, Color.BLACK));
62+
session.persist(new Cat("Bobby", 4, Color.BLACK));
63+
session.persist(new Cat("Harold", 5, Color.BLACK));
64+
session.persist(new Cat("Tim", 6, Color.BLACK));
6565
session.flush();
6666
}
6767
}

querydsl-libraries/querydsl-jpa/src/test/java/com/querydsl/jpa/IntegrationBase.java

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,8 @@ private HibernateInsertClause insert(EntityPath<?> entity) {
9898

9999
@Test
100100
public void scroll() {
101-
session.save(new Cat("Bob", 10));
102-
session.save(new Cat("Steve", 11));
101+
session.persist(new Cat("Bob", 10));
102+
session.persist(new Cat("Steve", 11));
103103

104104
var cat = QCat.cat;
105105
HibernateQuery<?> query = new HibernateQuery<Void>(session);
@@ -112,7 +112,7 @@ public void scroll() {
112112

113113
@Test
114114
public void insert() {
115-
session.save(new Cat("Bob", 10));
115+
session.persist(new Cat("Bob", 10));
116116

117117
var cat = QCat.cat;
118118
var amount = insert(cat).set(cat.name, "Bobby").set(cat.alive, false).execute();
@@ -123,7 +123,7 @@ public void insert() {
123123

124124
@Test
125125
public void insert2() {
126-
session.save(new Cat("Bob", 10));
126+
session.persist(new Cat("Bob", 10));
127127

128128
var cat = QCat.cat;
129129
var amount = insert(cat).columns(cat.name, cat.alive).values("Bobby", false).execute();
@@ -134,7 +134,7 @@ public void insert2() {
134134

135135
@Test
136136
public void insert3() {
137-
session.save(new Cat("Bob", 10));
137+
session.persist(new Cat("Bob", 10));
138138

139139
var cat = QCat.cat;
140140
var bob = new QCat("Bob");
@@ -151,8 +151,8 @@ public void insert3() {
151151

152152
@Test
153153
public void update() {
154-
session.save(new Cat("Bob", 10));
155-
session.save(new Cat("Steve", 11));
154+
session.persist(new Cat("Bob", 10));
155+
session.persist(new Cat("Steve", 11));
156156

157157
var cat = QCat.cat;
158158
var amount =
@@ -168,8 +168,8 @@ public void update() {
168168

169169
@Test
170170
public void update_with_null() {
171-
session.save(new Cat("Bob", 10));
172-
session.save(new Cat("Steve", 11));
171+
session.persist(new Cat("Bob", 10));
172+
session.persist(new Cat("Steve", 11));
173173

174174
var cat = QCat.cat;
175175
var amount =
@@ -183,8 +183,8 @@ public void update_with_null() {
183183

184184
@Test
185185
public void delete() {
186-
session.save(new Cat("Bob", 10));
187-
session.save(new Cat("Steve", 11));
186+
session.persist(new Cat("Bob", 10));
187+
session.persist(new Cat("Steve", 11));
188188

189189
var cat = QCat.cat;
190190
var amount = delete(cat).where(cat.name.eq("Bob")).execute();
@@ -195,7 +195,7 @@ public void delete() {
195195
public void collection() throws Exception {
196196
List<Cat> cats = Arrays.asList(new Cat("Bob", 10), new Cat("Steve", 11));
197197
for (Cat cat : cats) {
198-
session.save(cat);
198+
session.persist(cat);
199199
}
200200

201201
query().from(cat).innerJoin(cat.kittens, kitten).where(kitten.in(cats)).parse();

querydsl-libraries/querydsl-jpa/src/test/java/com/querydsl/jpa/UniqueResultsTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ public class UniqueResultsTest implements HibernateTest {
3232

3333
@Test
3434
public void test() {
35-
session.save(new Cat("Bob1", 1));
36-
session.save(new Cat("Bob2", 2));
37-
session.save(new Cat("Bob3", 3));
35+
session.persist(new Cat("Bob1", 1));
36+
session.persist(new Cat("Bob2", 2));
37+
session.persist(new Cat("Bob3", 3));
3838

3939
assertThat(
4040
query()

0 commit comments

Comments
 (0)