首页 > 解决方案 > 问题倾倒使用 JPA 实现 RepositoryCustom

问题描述

这是我的大问题这是代码

@Data
@Entity
@Table(name = "entity")
public class Entity extends AbstractField { 
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private BigInteger lookupValueKey;
private short lookupFieldKey;
private String lookupToken;
private String lookupValueFr;
private String lookupValueEn;
private BigInteger master1LookupValueKey;
private BigInteger master2LookupValueKey;
private BigInteger master3LookupValueKey;

public interface EntityRepository extends CrudRepository<Entity , BigInteger>,  
EntityRepositoryCustom {

}public interface EntityRepositoryCustom  {
List<Entity > inOnlyTest(Short groupId, String employerNum, Short EntityKey);

}@Repository
@Transactional(readOnly = true)
public class EntityRepositoryImp implements EntityRepositoryCustom {


@PersistenceContext
protected EntityManager em;
@Override
public List<LookupValue> inOnlyTest(Short groupId, String employerNum,
        Short lookupFieldKey) {
    StoredProcedureQuery query = em.createStoredProcedureQuery("EntityListbyKEY");
    query.registerStoredProcedureParameter(1, Short.class, ParameterMode.IN);
    .........

和错误

原因:java.lang.IllegalArgumentException:无法为方法 public abstract java.util.List com.bell.radar.demo.dao.LookupValueRepositoryCustom.inOnlyTest(java.lang.Short,java.lang.String,java. lang.Short)!未找到 LookupValue 类型的 inOnlyTest 属性!在 org.springframework.data.jpa.repository.query.PartTreeJpaQuery.(PartTreeJpaQuery.java:103) ~[spring-data-jpa-2.2.0.RELEASE.jar:2.2.0.RELEASE] 在 org.springframework.data .jpa.repository.query.JpaQueryLookupStrategy$CreateQueryLookupStrategy.resolveQuery(JpaQueryLookupStrategy.java:106) ~[spring-data-jpa-2.2.0.RELEASE.jar:2.2.0.RELEASE] 在 org.springframework.data.jpa。 repository.query.JpaQueryLookupStrategy$CreateIfNotFoundQueryLookupStrategy.resolveQuery(JpaQueryLookupStrategy.java:211) ~[spring-data-jpa-2.2.0.RELEASE.jar:2.2.0.RELEASE] at org。invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1862) ~[spring-beans-5.2.0.RELEASE.jar:5.2.0.RELEASE] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1799) ~ [spring-beans-5.2.0.RELEASE.jar:5.2.0.RELEASE] ...省略了59个常见框架原因:org.springframework.data.mapping.PropertyReferenceException:找不到类型LookupValue的inOnlyTest属性!在 org.springframework.data.mapping.PropertyPath.(PropertyPath.java:94) ~[spring-data-commons-2.2.0.RELEASE.jar:2.2.0.RELEASE] 在 org.springframework.data.mapping.PropertyPath .create(PropertyPath.java:382) ~[spring-data-commons-2.2.0.RELEASE.jar:2.2.0.RELEASE] at org.springframework.data.mapping.PropertyPath.create(PropertyPath.java:358) ~[spring-data-commons-2.2.0.

标签: javaspringspring-data-jpa

解决方案


实现的命名约定不正确

public class EntityRepositoryImp implements EntityRepositoryCustom {}

文档

与片段接口对应的类名中最重要的部分是Impl后缀。

将实现类重命名为EntityRepositoryImpl并尝试运行

更新 :

另一个观察是接口方法

List<Entity > inOnlyTest(

及其在实现中的覆盖

public List<LookupValue> inOnlyTest

不同步。错字?


推荐阅读