java - 问题倾倒使用 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.
解决方案
实现的命名约定不正确
public class EntityRepositoryImp implements EntityRepositoryCustom {}
从文档
与片段接口对应的类名中最重要的部分是Impl后缀。
将实现类重命名为EntityRepositoryImpl
并尝试运行
更新 :
另一个观察是接口方法
List<Entity > inOnlyTest(
及其在实现中的覆盖
public List<LookupValue> inOnlyTest
不同步。错字?
推荐阅读
- omnet++ - omnet 以路由协议重传数据包
- java - 无法从给定的缩短 URL 中获取扩展 URL
- javascript - 在角度 5 中单击时创建按钮微调器
- rxjs - 带有异步函数和 toPromise 的 Observable RxJS 有什么意外行为?
- javascript - 事件未在 socket.on('connect', event) 上调用
- apache - 如何为我的 jira 工具将 http 转换为 https
- javascript - 如何在 GET 方法中检查用户身份验证?
- firebase - 可调用函数支持缓存吗?
- environment-variables - 将 json 重命名为 *.environment.json 并且无法在邮递员中导入相同的内容
- java - 使用带有当前日期和 dob 和枚举的休眠保存学生