Skip to content

Commit 0513ad9

Browse files
authored
Merge pull request #10257 from geoand/#10208-do-over
Properly fix issue with primitive id types in Spring Data JPA.
2 parents 7c38b71 + daa4613 commit 0513ad9

File tree

2 files changed

+6
-3
lines changed
  • extensions/spring-data-jpa/deployment/src/main/java/io/quarkus/spring/data/deployment/generate
  • integration-tests/spring-data-jpa/src/main/java/io/quarkus/it/spring/data/jpa

2 files changed

+6
-3
lines changed

extensions/spring-data-jpa/deployment/src/main/java/io/quarkus/spring/data/deployment/generate/StockMethodsAdder.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,10 @@ private void generateSave(ClassCreator classCreator, FieldDescriptor entityClass
156156
throw new IllegalArgumentException("Id type of '" + entityDotName + "' is invalid.");
157157
}
158158
if (idType.name().equals(DotNames.PRIMITIVE_LONG)) {
159-
idValue = save.checkCast(idValue, int.class);
159+
ResultHandle longObject = save.invokeStaticMethod(
160+
MethodDescriptor.ofMethod(Long.class, "valueOf", Long.class, long.class), idValue);
161+
idValue = save.invokeVirtualMethod(MethodDescriptor.ofMethod(Long.class, "intValue", int.class),
162+
longObject);
160163
}
161164
BranchResult idValueNonZeroBranch = save.ifNonZero(idValue);
162165
idValueSet = idValueNonZeroBranch.trueBranch();

integration-tests/spring-data-jpa/src/main/java/io/quarkus/it/spring/data/jpa/Person.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public class Person {
2828
@Id
2929
@SequenceGenerator(name = "personSeqGen", sequenceName = "personSeq", initialValue = 100, allocationSize = 1)
3030
@GeneratedValue(generator = "personSeqGen")
31-
private Long id;
31+
private long id;
3232

3333
@JsonbProperty(nillable = true)
3434
private String name;
@@ -56,7 +56,7 @@ public Person(String name) {
5656
public Person() {
5757
}
5858

59-
public Long getId() {
59+
public long getId() {
6060
return id;
6161
}
6262

0 commit comments

Comments
 (0)