【发布时间】: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