简体   繁体   English

getTeamMapping是否应该从Spring-Data-JPA方法获取数据?

[英]getTeamMapping should get the data from Spring-Data-JPA method or not?

Have a look at the below code 看看下面的代码

teamMappingEntity = (List<TeamMappingEntity>) adminUtilityRequest
    .getTeamMappingRepository()
    .findAllByUserEntityAndIsDeleted(userEntity, Boolean.FALSE);

I am getting a NullPointerException at this line because getTeamMappingRepository in AdminUtilityRequest class is null at this point. 我得到一个NullPointerException ,在这条线,因为getTeamMappingRepositoryAdminUtilityRequest类是null在这一点上。 But what I don't understand is if I am calling the Spring-Data-JPA method findAllByUserEntityAndIsDeleted in the above line the data which I get from the Spring Data JPA method should be saved in getTeamMappingRepository but it doesn't. 但是我不明白的是,如果我在上一行中调用Spring-Data-JPA方法findAllByUserEntityAndIsDeleted ,我从Spring Data JPA方法获得的数据应该保存在getTeamMappingRepository但事实并非如此。 WHY???? 为什么????

Although this line works fine. 虽然这条线工作正常。

teamMappingEntity =  teamMappingRepository
    .findAllByUserEntityAndIsDeletedFalse(userEntity);

Any explanation will be appreciated. 任何解释将不胜感激。

if I am calling the Spring-Data-JPA method findAllByUserEntityAndIsDeleted in the above line the data which I get from the Spring Data JPA method should be saved in getTeamMappingRepository but it doesn't. 如果我在上一行中调用Spring-Data-JPA方法findAllByUserEntityAndIsDeleted ,则从Spring Data JPA方法获得的数据应保存在getTeamMappingRepository但不能保存。

Nope. 不。 findAllByUserEntityAndIsDeleted will return some data. findAllByUserEntityAndIsDeleted将返回一些数据。 That's it. 而已。 It won't store it anywhere. 它不会存储在任何地方。 And certainly not in getTeamMappingRepository : 并且肯定不在getTeamMappingRepository

  1. That is a method. 那是一种方法。 You can't store anything in a method. 您不能在方法中存储任何内容。 You would need a field for that. 您将需要一个字段。
  2. It is of the wrong type. 类型错误。 findAllByUserEntityAndIsDeleted returns a List , but getTeamMappingRepository returns a repository. findAllByUserEntityAndIsDeleted返回一个List ,但getTeamMappingRepository返回一个存储库。 Two very distinct things. 两件非常不同的事情。
  3. findAllByUserEntityAndIsDeleted doesn't contain any information about the existence of getTeamMappingRepository . findAllByUserEntityAndIsDeleted不包含有关getTeamMappingRepository存在的任何信息。 There is no way it can manipulate it in any way. 它无法以任何方式对其进行操作。

Your real problem is that there is no repository in adminUtilityRequest . 您的真正问题是adminUtilityRequest没有存储库。 We would need to see what you did to get a repository in there. 我们将需要查看您在其中获得存储库的操作。

Possibly you are missing an @Autowired annotation, or adminUtilityRequest is not a Spring bean so it doesn't get anything injected. 可能您缺少@Autowired批注,或者adminUtilityRequest不是Spring Bean,因此不会注入任何东西。

Probally in your adminUtilityRequest you need to add @Autowired annotation for "teamMappingRepository" attribute 可能在adminUtilityRequest您需要为"teamMappingRepository"属性添加@Autowired批注

If the annotation exist, maybe you object "adminUtilityRequest" was built manually outside of Spring context. 如果注释存在,则可能是您对象"adminUtilityRequest"是在Spring上下文外部手动构建的。 Should be good you review who this object is created. 最好检查一下此对象的创建者。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM