2017-08-08 68 views
-1

在Repositories中的Rest Spring API中,我需要通过三个参数来查找值,但这是phone,password,找到delete = 0。我已经将它添加到实体,但它显示错误无效的派生查询!找不到类型为CustomerEntity的属性!两个现场工作正常,但删除的工作不Spring Rest Repository Error

@Repository 
public interface CustomerRepository extends JpaRepository<CustomerEntity, Long> { 
CustomerEntity findByfacebookID(String facebookID); 
CustomerEntity findByPhoneAndPasswordAndIsDeleted(String phone, String password, Boolean isdeleted); 

实体

@Entity 
@Table(name = "CUSTOMER") 
public class CustomerEntity { 

    @Column(name = "IS_DELETED", length = 3, nullable = false) 
    private Boolean isdeleted; 
+0

为什么你在属性名称中有一个空格?完全在'私人布尔被删除' – DevDio

回答

0

春数据JPA假定您的字段名称遵循一定的约定,以便正确地生成导出查询。资本化问题; isdeleted != isDeleted。此外,IsXYZ在Spring Data JPA查询中有special meaning,并且可能会导致语法歧义。在一般情况下,墨守成规,事情就会简单得多:

@Repository 
public interface CustomerRepository extends JpaRepository<CustomerEntity, Long> { 
    CustomerEntity findByfacebookID(String facebookID); 

    CustomerEntity findByPhoneAndPasswordAndDeleted(String phone, String password, Boolean deleted); 
} 

@Entity 
@Table(name = "CUSTOMER") 
public class CustomerEntity { 

    @Column(name = "IS_DELETED", length = 3, nullable = false) 
    private Boolean deleted; 

    // phone, password, other fields... 
} 

简而言之:从你的布尔变量删除is前缀(即通常在访问的方法名称中使用,而不是在字段名称)。

+0

值得注意的是:根据你所看到的错误信息,简单地在'private布尔值中删除'd'被删除;'也可能解决这个问题,但是值得做完整的更新避免在您的查询中发现下一个更改时出现歧义。 – nbrooks

+0

感谢nbrooks它的工作是的这是d .i的问题必须使用它在小型大写字母Isdeleted – bkumar