使用spring crudRepository访问数据时出错:找不到类的必需标识符属性

时间:2019-12-18 23:01:29

标签: spring spring-boot jpa

实体类:

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;

@Entity
@Table(name="champion")
public class Champion {

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Integer id;
    private String name;
    private Integer age;
    @Column(name = "home_town")
    private String homeTown;
    @Column(name = "action_ground")
    private String actionGround;
    @Column(name = "created_at")
    private String createdAt;
    @Column(name = "updated_at")
    private String updatedAt;

    // getters setters
}

存储库类:

@Repository
public interface ChampionRepository extends CrudRepository<Champion, Integer>{

    public Optional<Champion> findById(Integer id);
}

控制台日志:

java.lang.IllegalStateException:找不到类com.marvel.domain.Champion所需的标识符属性!     在org.springframework.data.mapping.PersistentEntity.getRequiredIdProperty(PersistentEntity.java:105)〜[spring-data-commons-2.2.3.RELEASE.jar:2.2.3.RELEASE]     在org.springframework.data.relational.core.mapping.RelationalPersistentEntityImpl.getIdColumn(RelationalPersistentEntityImpl.java:71)〜[spring-data-relational-1.1.3.RELEASE.jar:1.1.3.RELEASE]     在org.springframework.data.jdbc.core.convert.SqlContext.getIdColumn(SqlContext.java:42)〜[spring-data-jdbc-1.1.3.RELEASE.jar:1.1.3.RELEASE]     在org.springframework.data.jdbc.core.convert.SqlGenerator.getIdColumn(SqlGenerator.java:551)〜[spring-data-jdbc-1.1.3.RELEASE.jar:1.1.3.RELEASE]     在org.springframework.data.jdbc.core.convert.SqlGenerator.createFindOneSql(SqlGenerator.java:304)〜

0 个答案:

没有答案