-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Closed
Description
Having repository definition
public interface UserRepository extends JpaRepository<UserEntity, Long> {
..........
@Lock(LockModeType.PESSIMISTIC_WRITE)
@QueryHints({@QueryHint(name = "jakarta.persistence.lock.timeout", value = "10000")})
Optional<UserEntity> findByIdAndIdIsNotNull(Long id);
...................
./gradlew clean nativeCompile
generates UserRepositoryImpl__AotRepository
public Optional<UserEntity> findByIdAndIdIsNotNull(Long id) {
String queryString = "SELECT u FROM UserEntity u WHERE u.id = :id AND u.id IS NOT NULL";
Query query = this.entityManager.createQuery(queryString);
query.setHint("jakarta.persistence.lock.timeout", "10000");
query.setParameter("id", id);
return Optional.ofNullable((UserEntity) convertOne(query.getSingleResultOrNull(), false, UserEntity.class));
}
and not sets lock mode to query (query.setLockMode(LockModeType.PESSIMISTIC_WRITE))
I think it should be added in JpaRepositoryContributor where other annotations are processed like:
MergedAnnotation<NativeQuery> nativeQuery = context.getAnnotation(NativeQuery.class);
MergedAnnotation<QueryHints> queryHints = context.getAnnotation(QueryHints.class);
MergedAnnotation<EntityGraph> entityGraph = context.getAnnotation(EntityGraph.class);
MergedAnnotation<Modifying> modifying = context.getAnnotation(Modifying.class);
adding MergedAnnotation<Lock> lock = context.getAnnotation(Lock.class); and pass CodeBlock.Builder for processing
The only way to resolve issue, to disable code generation with:
spring:
aot:
repositories:
enabled: false
steps to reproduce
-
Run:
./gradlew nativeCompile -
Inspect generated code:
build/generated/aotSources/.../UserRepositoryImpl__AotRepository.java
or the compiled class.
Reactions are currently unavailable