小编And*_*sev的帖子

x如何使用 Spring Data JPA 在 Spring 中为 CrudRepository 设置 @Id 字符串?

问题是我在使用@RepositoryRestResource我的UserRepository扩展时遇到了异常JpaRepository

原因是默认情况下findById只接受Long或输入Int,即使我有

@Id String id;而不是@Id Int id在我的实体定义中。

我尝试搜索 StackOverflow 和 Google,但没有找到任何解决方案。

错误信息如下:

"Failed to convert from type [java.lang.String] to type [java.lang.Integer] for value '3175433272470683'; nested exception is java.lang.NumberFormatException: For input string: \"3175433272470683\""

我想让它与

@Id String id;

有什么建议?

非常感谢提前。在这里提问是我的荣幸。

实体类:

@Entity // This tells Hibernate to make a table out of this class
@Table(name = "users")
public class XmppUser {
    @Id
    private java.lang.String username;

    private String …
Run Code Online (Sandbox Code Playgroud)

java spring hibernate spring-data-jpa spring-hateoas

3
推荐指数
1
解决办法
6930
查看次数