Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@
<r2dbc.version>1.0.0.RELEASE</r2dbc.version>

<!-- JPA deps -->
<hibernate.version>7.2.6.Final</hibernate.version>
<hibernate.version>7.3.1.Final</hibernate.version>
<hibernate.validator.version>9.1.0.Final</hibernate.validator.version>
<eclipselink.version>5.0.0-B13</eclipselink.version>
<jpa.version>3.2.0</jpa.version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -427,10 +427,10 @@ public Void visit(SubQueryExpression<?> query, Void context) {
&& modifiers.isRestricting()
&& templates.isSubQueryModifiersSupported()) {
if (modifiers.getLimit() != null) {
append(LIMIT).handle(modifiers.getLimit());
append(LIMIT).handle(modifiers.getLimitAsInteger());
}
if (modifiers.getOffset() != null) {
append(OFFSET).handle(modifiers.getOffset());
append(OFFSET).handle(modifiers.getOffsetAsInteger());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,6 @@ private static void setValueWithNumberedLabel(
query.setParameterList(key, collection);
} else if (val instanceof Object[] objects && !BUILT_IN.contains(val.getClass())) {
query.setParameterList(key, objects);
} else if (val instanceof Number && TYPES.containsKey(val.getClass())) {
query.setParameter(key, val, getType(val.getClass()));
} else {
query.setParameter(key, val);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,20 @@
*/
public final class JPAUtil {

private static final Map<Class<?>, Class<?>> PRIMITIVE_TO_WRAPPER =
Map.of(
int.class, Integer.class,
long.class, Long.class,
double.class, Double.class,
float.class, Float.class,
short.class, Short.class,
byte.class, Byte.class);

@SuppressWarnings("unchecked")
private static <T extends Number> Class<T> primitiveToWrapper(Class<?> type) {
return (Class<T>) PRIMITIVE_TO_WRAPPER.getOrDefault(type, type);
}

private JPAUtil() {}

public static void setConstants(
Expand All @@ -50,8 +64,9 @@ public static void setConstants(
Parameter parameter = query.getParameter(i + 1);
var parameterType = parameter != null ? parameter.getParameterType() : null;
if (parameterType != null && !parameterType.isInstance(val)) {
if (val instanceof Number number && Number.class.isAssignableFrom(parameterType)) {
val = MathUtils.cast(number, parameterType);
var targetType = primitiveToWrapper(parameterType);
if (val instanceof Number number && Number.class.isAssignableFrom(targetType)) {
val = MathUtils.cast(number, targetType);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ public void visit_subQueryExpression_with_limit_hql() {

assertThat(serializer.toString()).isEqualTo("(select cat.id\nfrom Cat cat\nlimit ?1)");
assertThat(serializer.getConstants()).hasSize(1);
assertThat(serializer.getConstants().getFirst()).isEqualTo(5L);
assertThat(serializer.getConstants().getFirst()).isEqualTo(5);
}

@Test
Expand All @@ -418,7 +418,7 @@ public void visit_subQueryExpression_with_offset_hql() {

assertThat(serializer.toString()).isEqualTo("(select cat.id\nfrom Cat cat\noffset ?1)");
assertThat(serializer.getConstants()).hasSize(1);
assertThat(serializer.getConstants().getFirst()).isEqualTo(10L);
assertThat(serializer.getConstants().getFirst()).isEqualTo(10);
}

@Test
Expand All @@ -442,8 +442,8 @@ public void visit_subQueryExpression_with_limit_and_offset_hql() {
assertThat(serializer.toString())
.isEqualTo("(select cat.id\nfrom Cat cat\nlimit ?1\noffset ?2)");
assertThat(serializer.getConstants()).hasSize(2);
assertThat(serializer.getConstants().get(0)).isEqualTo(5L);
assertThat(serializer.getConstants().get(1)).isEqualTo(10L);
assertThat(serializer.getConstants().get(0)).isEqualTo(5);
assertThat(serializer.getConstants().get(1)).isEqualTo(10);
}

@Test
Expand All @@ -469,8 +469,8 @@ where cat.id in (select mate.id
limit ?1)
limit ?2)""");
assertThat(serializer.getConstants()).hasSize(2);
assertThat(serializer.getConstants().get(0)).isEqualTo(3L);
assertThat(serializer.getConstants().get(1)).isEqualTo(5L);
assertThat(serializer.getConstants().get(0)).isEqualTo(3);
assertThat(serializer.getConstants().get(1)).isEqualTo(5);
}

@Test
Expand Down Expand Up @@ -537,8 +537,8 @@ where cat.id in (select kitten.id
limit ?1
offset ?2)""");
assertThat(hqlSerializer.getConstants()).hasSize(2);
assertThat(hqlSerializer.getConstants().get(0)).isEqualTo(5L);
assertThat(hqlSerializer.getConstants().get(1)).isEqualTo(10L);
assertThat(hqlSerializer.getConstants().get(0)).isEqualTo(5);
assertThat(hqlSerializer.getConstants().get(1)).isEqualTo(10);
}

@Test
Expand Down Expand Up @@ -601,7 +601,7 @@ public void subquery_in_select_clause_with_modifiers_hql() {
offset ?2)
from Cat cat""");
assertThat(hqlSerializer.getConstants()).hasSize(2);
assertThat(hqlSerializer.getConstants().get(0)).isEqualTo(1L);
assertThat(hqlSerializer.getConstants().get(1)).isEqualTo(2L);
assertThat(hqlSerializer.getConstants().get(0)).isEqualTo(1);
assertThat(hqlSerializer.getConstants().get(1)).isEqualTo(2);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,15 @@ public void test() throws IOException {
var origFile = origRoot.toPath().resolve(relativeFile);
var reference = new String(Files.readAllBytes(origFile), StandardCharsets.UTF_8);
var content = new String(Files.readAllBytes(file.toPath()), StandardCharsets.UTF_8);

if (file.getName().equals("QCalendar.java")) {
// The APT processor does not apply @Temporal(TemporalType.DATE) to @ElementCollection
// map values, so it generates DateTimePath for java.util.Date. The JPADomainExporter
// correctly reads @Temporal from the Hibernate metamodel and generates DatePath.
// Hibernate 7.3+ fixed metamodel exposure of @Temporal for map attributes.
reference = reference.replace("DateTimePath", "DatePath");
}

assertThat(content).as("Mismatch for " + file.getName() + "\n").isEqualTo(reference);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,15 @@ public void test() throws IOException {
var reference =
new String(java.nio.file.Files.readAllBytes(origFile), StandardCharsets.UTF_8);
var content = new String(Files.readAllBytes(file.toPath()), StandardCharsets.UTF_8);

if (file.getName().equals("QCalendar.java")) {
// The APT processor does not apply @Temporal(TemporalType.DATE) to @ElementCollection
// map values, so it generates DateTimePath for java.util.Date. The JPADomainExporter
// correctly reads @Temporal from the Hibernate metamodel and generates DatePath.
// Hibernate 7.3+ fixed metamodel exposure of @Temporal for map attributes.
reference = reference.replace("DateTimePath", "DatePath");
}

assertThat(content).withFailMessage("Mismatch for %s", file.getPath()).isEqualTo(reference);
}
}
Expand Down
Loading