【发布时间】:2018-04-07 17:44:56
【问题描述】:
我有这个 Spring Boot 应用程序,我有一个配置文件实体,我有我的存储库。
问题是,当我通过电子邮件对某个配置文件进行第二次查询时,该对象返回非空,但其中没有数据,因此我无法比较该对象的数据。
我的仓库:
public interface ProfileRepository extends JpaRepository<Profile, Long> {
Profile findById(Long id);
@Query("select e from Profile e where e.email = ?1")
Profile findByEmail(String email);
}
执行这些查询的代码:
Profile myProfile = this.profileRepository.findById(data.getIdMyProfile());
Profile hisProfile = this.profileRepository.findByEmail(data.getEmail()); // see this one on the image - here is the problem
Card myCard = this.cardRepository.findById(data.getIdMyCard());
我意识到,如果我连续对 Profile 实体进行 2 次查询,就会发生这种情况,我反转查询以查看差异,第二个对象不为空,但根本没有数据。
知道为什么会出现这个问题吗?
【问题讨论】:
-
尝试删除 @query 注释,因为您不需要任何自定义查询,只需简单的存储库检索。
-
我确实删除了@Query 注释,同样的结果,我认为是别的,因为在另一种方法中查询适用于电子邮件。
标签: spring hibernate spring-boot