【发布时间】:2018-10-05 07:58:37
【问题描述】:
我有以下实体:
@Entity
@Table(name = "MY_TABLE")
@Data
public class MyTable implements java.io.Serializable {
private static final long serialVersionUID = 3879471087851341216L;
@Id
@Column(name = "MY_ID")
private BigInteger myId;
@Column(name = "ANOTHER_COL")
private String anotherColumn;
然后我创建我的存储库:
@Repository
public interface MyTableRepository extends JpaRepository<MyTable, BigInteger> {
@Query(name = "select count(*) from MyTable where ...")
public Long getCountOf(@Param("myId") BigInteger myId);
但我一开始就收到了:
未找到类型 MyTable 的属性 getCountOf
我做错了什么?
【问题讨论】:
-
您不需要提供明确的查询。 Spring-data-jpa 可以为您生成它。只需尝试将您的方法替换为
long countByMyId(BigInteger myId);
标签: hibernate spring-boot spring-data-jpa