【问题标题】:Spring Data with Neo4j throwing IllegalArgumentException when using Integer id使用 Integer id 时 Neo4j 的 Spring Data 抛出 IllegalArgumentException
【发布时间】:2020-09-18 22:37:12
【问题描述】:
import org.springframework.data.repository.CrudRepository;
import com.neo.Model.Team;
public interface TeamRepository extends CrudRepository<Team, Integer> {

}

这是一个用于 CRUD 操作的简单团队存储库。我还使用检索 Team 类的对象的方法创建了一个服务类(如下所示)-

public Team retrieveTeam(Integer id) throws NotFoundException {
        
        Optional<Team> p=team.findById(id);
        return p.orElseThrow(()->new NotFoundException());
        
}

团队类本身是这样的-

public class Team {
    
    @Id
    private int id;
    private int win;
    private int loss;
    private int draw;
    private String form;
    private String name;
}

getter 和 setter 由 Lombok 定义。目前我正在将一个 int 变量传递给服务方法,但我已经尝试了所有组合。我尝试从 int 值创建新的 Integer 对象,我尝试在 retrieveTeam 方法中使用 int 参数,然后在 findById 中简单地使用 int 值,但没有一个有效。此外,id 不是生成的,而是在保存对象时由我传递的。我不断收到此错误-

java.lang.IllegalArgumentException: Supplied id does not match primary index type on supplied class com.neo.Model.Team

我在这里错过了什么?

【问题讨论】:

    标签: spring-data spring-data-neo4j


    【解决方案1】:

    非常简单的错误。我应该在 Team 类中声明 Integer id 而不是 int id。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-12-15
      • 1970-01-01
      • 2019-02-20
      • 1970-01-01
      • 2018-08-30
      • 1970-01-01
      相关资源
      最近更新 更多