我有以下实体:
@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
我在做什么错了?
答案 0 :(得分:0)
我怀疑该方法的命名误导了spring-jpa。
spring-data还可以为您自动生成计数查询,只要您遵循正确的命名约定,则无需提供该查询:
@Repository
public interface MyTableRepository extends JpaRepository<MyTable, BigInteger> {
long countByMyId(BigInteger myId);
}