@Id
@Type(value = OptimizedUUIDType.class)
@OptimizedUUID
private UUID id;
public class OptimizedUUIDConverter implements BasicValueConverter<UUID, Object> {
@Override
public UUID toDomainValue(Object bytes) {
byte[] msb = new byte[8];
byte[] lsb = new byte[8];
// Reorder the UUID, swapping the hi- and low- digits of the timestamp
arraycopy(bytes, 4, msb, 0, 4);
arraycopy(bytes, 2, msb, 4, 2);
arraycopy(bytes, 0, msb, 6, 2);
// The remainder of the UUID (clock sequence and MAC address) are kept as-is
arraycopy(bytes, 8, lsb, 0, 8);
return new UUID(asLong(msb), asLong(lsb));
}
@Override
public Object toRelationalValue(UUID uuid) {
final byte[] out = new byte[16];
final byte[] msbIn = fromLong(uuid.getMostSignificantBits());
// Reorder the UUID, swapping the hi- and low- digits of the timestamp
arraycopy(msbIn, 6, out, 0, 2);
arraycopy(msbIn, 4, out, 2, 2);
arraycopy(msbIn, 0, out, 4, 4);
// The remainder of the UUID (clock sequence and MAC address) are kept as-is
arraycopy(fromLong(uuid.getLeastSignificantBits()), 0, out, 8, 8);
return out;
}
@Override
public JavaType<UUID> getDomainJavaType() {
return OptimizedUUIDTypeDescriptor.INSTANCE;
}
@Override
public JavaType<Object> getRelationalJavaType() {
return ObjectJavaType.INSTANCE;
}
}
serverRepository.findAllByIdIn(List.of());
Caused by: java.lang.NullPointerException: Cannot invoke "java.util.UUID.getMostSignificantBits()" because "uuid" is null
at com.example.demo.OptimizedUUIDConverter.toRelationalValue(OptimizedUUIDConverter.java:40) ~[main/:na]
at com.example.demo.OptimizedUUIDConverter.toRelationalValue(OptimizedUUIDConverter.java:18) ~[main/:na]
at org.hibernate.query.sqm.internal.SqmUtil.createJdbcParameterBindings(SqmUtil.java:499) ~[hibernate-core-6.5.3.Final.jar:6.5.3.Final]
at org.hibernate.query.sqm.internal.ConcreteSqmSelectQueryPlan.buildCacheableSqmInterpretation(ConcreteSqmSelectQueryPlan.java:433) ~[hibernate-core-6.5.3.Final.jar:6.5.3.Final]
at org.hibernate.query.sqm.internal.ConcreteSqmSelectQueryPlan.withCacheableSqmInterpretation(ConcreteSqmSelectQueryPlan.java:328) ~[hibernate-core-6.5.3.Final.jar:6.5.3.Final]
at org.hibernate.query.sqm.internal.ConcreteSqmSelectQueryPlan.performList(ConcreteSqmSelectQueryPlan.java:302) ~[hibernate-core-6.5.3.Final.jar:6.5.3.Final]
at org.hibernate.query.sqm.internal.QuerySqmImpl.doList(QuerySqmImpl.java:526) ~[hibernate-core-6.5.3.Final.jar:6.5.3.Final]
at org.hibernate.query.spi.AbstractSelectionQuery.list(AbstractSelectionQuery.java:423) ~[hibernate-core-6.5.3.Final.jar:6.5.3.Final]
at org.hibernate.query.Query.getResultList(Query.java:120) ~[hibernate-core-6.5.3.Final.jar:6.5.3.Final]
at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103) ~[na:na]
at java.base/java.lang.reflect.Method.invoke(Method.java:580) ~[na:na]
at org.springframework.orm.jpa.SharedEntityManagerCreator$DeferredQueryInvocationHandler.invoke(SharedEntityManagerCreator.java:418) ~[spring-orm-6.1.14.jar:6.1.14]
at jdk.proxy2/jdk.proxy2.$Proxy107.getResultList(Unknown Source) ~[na:na]
at org.springframework.data.jpa.repository.query.JpaQueryExecution$CollectionExecution.doExecute(JpaQueryExecution.java:129) ~[spring-data-jpa-3.3.5.jar:3.3.5]
at org.springframework.data.jpa.repository.query.JpaQueryExecution.execute(JpaQueryExecution.java:92) ~[spring-data-jpa-3.3.5.jar:3.3.5]
at org.springframework.data.jpa.repository.query.AbstractJpaQuery.doExecute(AbstractJpaQuery.java:152) ~[spring-data-jpa-3.3.5.jar:3.3.5]
Why is the toRelationalValue method in Converter also called when querying an empty collection?
Although it can be solved by adding judgment in Converter
But I want to know why