Я использую Springboot 2.1.2 и сталкиваюсь с некоторыми проблемами с репозиторием.
Вот мои классы сущности: < /p>
@Entity
@Getter
@Setter
@NoArgsConstructor
@Table(name = "orders")
public class Order {
@Id
@GeneratedValue
private long id;
@ManyToOne(targetEntity = User.class)
private User user;
//other fields and getters and setters are ignored
}
@Entity
@Getter
@Setter
@NoArgsConstructor
public class User {
@Id
private String email;
//other fields and getters and setters are ignored
}
< /code>
и My OrderRepository: < /p>
@Repository
public interface OrderRepository extends JpaRepository {
@Query("select o from Order o where o.user.email = ?1")
List findAllByUserId(String userId);
List findAllByUser(User user);
}
< /code>
Когда я вызываю findallbyuserid или findallbyuser, репозиторий возвращает Null Value < /strong> вместо пустого списка < /strong>, это так странно, поскольку я уверен, что в моей базе данных есть данные. /> Я пытаюсь решить проблему с отладчиком, и я отслеживаю в классе asyncexcutionInterceptor < /strong>: < /p>
@Nullable
public Object invoke(MethodInvocation invocation) throws Throwable {
Class targetClass = invocation.getThis() != null ? AopUtils.getTargetClass(invocation.getThis()) : null;
Method specificMethod = ClassUtils.getMostSpecificMethod(invocation.getMethod(), targetClass);
Method userDeclaredMethod = BridgeMethodResolver.findBridgedMethod(specificMethod);
AsyncTaskExecutor executor = this.determineAsyncExecutor(userDeclaredMethod);
if (executor == null) {
throw new IllegalStateException("No executor specified and no default executor set on AsyncExecutionInterceptor either");
} else {
Callable task = () -> {
try {
Object result = invocation.proceed();
if (result instanceof Future) {
return ((Future)result).get();
}
} catch (ExecutionException var4) {
this.handleError(var4.getCause(), userDeclaredMethod, invocation.getArguments());
} catch (Throwable var5) {
this.handleError(var5, userDeclaredMethod, invocation.getArguments());
}
return null;
};
return this.doSubmit(task, executor, invocation.getMethod().getReturnType());
}
}
< /code>
и я замечаю, что в 13 -й строке этого метода результатом переменной является список с надлежащими объектами порядка, но предложение if не удается и, таким образом, возвращает нулевое значение. < /p>
Так кто -нибудь знает, как решить проблему? < /p>
============================================================================================================== />
Подробнее здесь: https://stackoverflow.com/questions/548 ... empty-list
SpringData JPA Repository findallbyxxx () return null вместо пустого списка ⇐ JAVA
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение
-
-
Репозиторий Springdata JPA findAllByXXX() возвращает значение null вместо пустого списка
Anonymous » » в форуме JAVA - 0 Ответы
- 26 Просмотры
-
Последнее сообщение Anonymous
-
-
-
Репозиторий Springdata JPA findAllByXXX() возвращает значение null вместо пустого списка
Anonymous » » в форуме JAVA - 0 Ответы
- 26 Просмотры
-
Последнее сообщение Anonymous
-
-
-
Репозиторий Springdata JPA findAllByXXX() возвращает значение null вместо пустого списка
Anonymous » » в форуме JAVA - 0 Ответы
- 26 Просмотры
-
Последнее сообщение Anonymous
-
-
-
Задача по электронной почте return return return, но не отправляйте электронную почту, иногда
Anonymous » » в форуме Php - 0 Ответы
- 15 Просмотры
-
Последнее сообщение Anonymous
-