【发布时间】:2021-03-15 18:29:57
【问题描述】:
我正在尝试在数据库中保存一条记录,作为回报应该返回我主键。
这是我的实体类:
@Entity
public class CustomEntity {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
Long id;
private Integer eventTypeId;
//getter setter here
}
这是我的存储库:
public interface CustomRepository extends JpaRepository<CustomEntity, Long> {
Long save(customRepository);
}
当我尝试在我的服务类中调用存储库接口时,我在编译时收到此异常:
Error:(32, 8) java: save(model.CustomEntity) in repository.CustomRepository clashes with <S>save(S)
in org.springframework.data.repository.CrudRepository return type java.lang.Long is not compatible with S
我了解 JPA Repository 扩展了 PaginationAndSorting,它在返回中扩展了 CrudRepository,我该如何解决这个问题。
【问题讨论】: