【问题标题】:Spring-JPA repository custom behaviourSpring-JPA 存储库自定义行为
【发布时间】:2015-11-24 14:16:43
【问题描述】:

我已按照 Spring-Data-JPA 参考将自定义行为添加到我的存储库之一。但是我在运行时收到“找不到类型的属性”错误。 不确定我在代码中哪里做错了,或者在配置中遗漏了任何东西。 谢谢你的帮助。

自定义行为:

public interface JobStatusRepositoryCustom {
    JobStatusEntity retrieveJobStatus(int projectId, int jobId, int executionId);
}

public class JobStatusRepositoryImpl implements JobStatusRepositoryCustom {
    @PersistenceContext
    private EntityManager entityManager;

    @Override
    public JobStatusEntity retrieveJobStatus(int projectId, int jobId, int executionId) {
        String query = "SELECT e.* FROM JobStatusEntity e WHERE e.projectId=? AND e.jobId=? AND e.executionId=?";
        return (JobStatusEntity)entityManager.createQuery(query)
                .setParameter(1, projectId)
                .setParameter(2,  jobId)
                .setParameter(3, executionId)
                .getSingleResult();
    }
}

主存储库接口:

public interface JobStatusRespository extends JpaRepository<JobStatusEntity, Integer>, JobStatusRepositoryCustom {
}

配置:

@EnableJpaRepositories( {"com.alu.mdm.*.repository", "com.alu.mdm.*.dao" })
上面的运行时异常:

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jobStatusRespository': Invocation of init method failed; nested exception is org.springframework.data.mapping.PropertyReferenceException: No property retrieveJobStatus found for type JobStatusEntity!
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1572) ~[spring-beans-4.1.8.RELEASE.jar:4.1.8.RELEASE]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:539) ~[spring-beans-4.1.8.RELEASE.jar:4.1.8.RELEASE]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476) ~[spring-beans-4.1.8.RELEASE.jar:4.1.8.RELEASE]
	at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:303) ~[spring-beans-4.1.8.RELEASE.jar:4.1.8.RELEASE]
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.1.8.RELEASE.jar:4.1.8.RELEASE]
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:299) ~[spring-beans-4.1.8.RELEASE.jar:4.1.8.RELEASE]
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194) ~[spring-beans-4.1.8.RELEASE.jar:4.1.8.RELEASE]
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:736) ~[spring-beans-4.1.8.RELEASE.jar:4.1.8.RELEASE]
	at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:759) ~[spring-context-4.1.8.RELEASE.jar:4.1.8.RELEASE]
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:480) ~[spring-context-4.1.8.RELEASE.jar:4.1.8.RELEASE]
	at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:125) ~[spring-test-4.1.8.RELEASE.jar:4.1.8.RELEASE]
	at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:60) ~[spring-test-4.1.8.RELEASE.jar:4.1.8.RELEASE]
	at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.delegateLoading(AbstractDelegatingSmartContextLoader.java:109) ~[spring-test-4.1.8.RELEASE.jar:4.1.8.RELEASE]
	at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.loadContext(AbstractDelegatingSmartContextLoader.java:261) ~[spring-test-4.1.8.RELEASE.jar:4.1.8.RELEASE]
	at org.springframework.test.context.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:68) ~[spring-test-4.1.8.RELEASE.jar:4.1.8.RELEASE]
	at org.springframework.test.context.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:86) ~[spring-test-4.1.8.RELEASE.jar:4.1.8.RELEASE]
	... 25 common frames omitted
Caused by: org.springframework.data.mapping.PropertyReferenceException: No property retrieveJobStatus found for type JobStatusEntity!
	at org.springframework.data.mapping.PropertyPath.<init>(PropertyPath.java:75) ~[spring-data-commons-1.9.4.RELEASE.jar:na]
	at org.springframework.data.mapping.PropertyPath.create(PropertyPath.java:327) ~[spring-data-commons-1.9.4.RELEASE.jar:na]
	at org.springframework.data.mapping.PropertyPath.create(PropertyPath.java:307) ~[spring-data-commons-1.9.4.RELEASE.jar:na]
	at org.springframework.data.mapping.PropertyPath.from(PropertyPath.java:270) ~[spring-data-commons-1.9.4.RELEASE.jar:na]
	at org.springframework.data.mapping.PropertyPath.from(PropertyPath.java:241) ~[spring-data-commons-1.9.4.RELEASE.jar:na]
	at org.springframework.data.repository.query.parser.Part.<init>(Part.java:76) ~[spring-data-commons-1.9.4.RELEASE.jar:na]
	at org.springframework.data.repository.query.parser.PartTree$OrPart.<init>(PartTree.java:235) ~[spring-data-commons-1.9.4.RELEASE.jar:na]
	at org.springframework.data.repository.query.parser.PartTree$Predicate.buildTree(PartTree.java:373) ~[spring-data-commons-1.9.4.RELEASE.jar:na]
	at org.springframework.data.repository.query.parser.PartTree$Predicate.<init>(PartTree.java:353) ~[spring-data-commons-1.9.4.RELEASE.jar:na]
	at org.springframework.data.repository.query.parser.PartTree.<init>(PartTree.java:84) ~[spring-data-commons-1.9.4.RELEASE.jar:na]
	at org.springframework.data.jpa.repository.query.PartTreeJpaQuery.<init>(PartTreeJpaQuery.java:61) ~[spring-data-jpa-1.7.4.RELEASE.jar:na]
	at org.springframework.data.jpa.repository.query.JpaQueryLookupStrategy$CreateQueryLookupStrategy.resolveQuery(JpaQueryLookupStrategy.java:94) ~[spring-data-jpa-1.7.4.RELEASE.jar:na]
	at org.springframework.data.jpa.repository.query.JpaQueryLookupStrategy$CreateIfNotFoundQueryLookupStrategy.resolveQuery(JpaQueryLookupStrategy.java:205) ~[spring-data-jpa-1.7.4.RELEASE.jar:na]
	at org.springframework.data.jpa.repository.query.JpaQueryLookupStrategy$AbstractQueryLookupStrategy.resolveQuery(JpaQueryLookupStrategy.java:72) ~[spring-data-jpa-1.7.4.RELEASE.jar:na]
	at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.<init>(RepositoryFactorySupport.java:369) ~[spring-data-commons-1.9.4.RELEASE.jar:na]
	at org.springframework.data.repository.core.support.RepositoryFactorySupport.getRepository(RepositoryFactorySupport.java:192) ~[spring-data-commons-1.9.4.RELEASE.jar:na]
	at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.initAndReturn(RepositoryFactoryBeanSupport.java:239) ~[spring-data-commons-1.9.4.RELEASE.jar:na]
	at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.afterPropertiesSet(RepositoryFactoryBeanSupport.java:225) ~[spring-data-commons-1.9.4.RELEASE.jar:na]
	at org.springframework.data.jpa.repository.support.JpaRepositoryFactoryBean.afterPropertiesSet(JpaRepositoryFactoryBean.java:92) ~[spring-data-jpa-1.7.4.RELEASE.jar:na]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1631) ~[spring-beans-4.1.8.RELEASE.jar:4.1.8.RELEASE]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1568) ~[spring-beans-4.1.8.RELEASE.jar:4.1.8.RELEASE]
	... 40 common frames omitted

【问题讨论】:

    标签: spring jpa repository


    【解决方案1】:

    我想你只是打错了:

    公共接口 JobStatusRes存储库

    【讨论】:

      猜你喜欢
      • 2018-10-06
      • 1970-01-01
      • 2017-11-15
      • 2021-04-01
      • 1970-01-01
      • 2012-05-18
      • 2015-03-15
      • 1970-01-01
      • 2012-06-02
      相关资源
      最近更新 更多