Java 使用2种相同方法的jpa存储库
我正在JPA存储库中尝试添加两个相同的方法名。我不确定这是否可能 这就是我在JPA接口中实际要做的:Java 使用2种相同方法的jpa存储库,java,hibernate,jpa,Java,Hibernate,Jpa,我正在JPA存储库中尝试添加两个相同的方法名。我不确定这是否可能 这就是我在JPA接口中实际要做的: public interface TbiDDCustomQueryConfigDao extends CrudRepository<TbiDDCustomQueryConfig, Integer>, JpaRepository<TbiDDCustomQueryConfig, Integer>{ @Query("select c from TbiDDCustomQ
public interface TbiDDCustomQueryConfigDao extends CrudRepository<TbiDDCustomQueryConfig, Integer>, JpaRepository<TbiDDCustomQueryConfig, Integer>{
@Query("select c from TbiDDCustomQueryConfig c, TbiDataSource d where c.datasourceId= d.dataSourceId and c.tbiDDConfigMaster.ddConfigId = ?1 and c.isActive = ?2 and d.isActive='Y'")
List<TbiDDCustomQueryConfig> findByDdConfigIdAndIsActive(Integer ddConfigId,String isActive);
TbiDDCustomQueryConfig findByDdConfigIdAndIsActive(Integer ddConfigId,String isActive);
}
但是当我运行代码时,我得到了一个错误:
Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.acinfotech.timebound.jpa.dao.TbiDDCustomQueryConfigDao com.acinfotech.timebound.jpa.service.ReportJobsPersistenceServiceImpl.tbiDDCustomQueryDao; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'tbiDDCustomQueryConfigDao': Invocation of init method failed; nested exception is org.springframework.data.mapping.PropertyReferenceException: No property dd found for type TbiDDCustomQueryConfig!
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:517)
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:87)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:286)
... 48 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'tbiDDCustomQueryConfigDao': Invocation of init method failed; nested exception is org.springframework.data.mapping.PropertyReferenceException: No property dd found for type TbiDDCustomQueryConfig!
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1512)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:521)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:458)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:296)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:293)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:912)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:855)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:770)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:489)
... 50 more
Caused by: org.springframework.data.mapping.PropertyReferenceException: No property dd found for type TbiDDCustomQueryConfig!
at org.springframework.data.mapping.PropertyPath.<init>(PropertyPath.java:75)
at org.springframework.data.mapping.PropertyPath.create(PropertyPath.java:327)
at org.springframework.data.mapping.PropertyPath.create(PropertyPath.java:359)
at org.springframework.data.mapping.PropertyPath.create(PropertyPath.java:359)
at org.springframework.data.mapping.PropertyPath.create(PropertyPath.java:307)
at org.springframework.data.mapping.PropertyPath.from(PropertyPath.java:270)
at org.springframework.data.mapping.PropertyPath.from(PropertyPath.java:241)
at org.springframework.data.repository.query.parser.Part.<init>(Part.java:76)
at org.springframework.data.repository.query.parser.PartTree$OrPart.<init>(PartTree.java:201)
at org.springframework.data.repository.query.parser.PartTree$Predicate.buildTree(PartTree.java:291)
at org.springframework.data.repository.query.parser.PartTree$Predicate.<init>(PartTree.java:271)
at org.springframework.data.repository.query.parser.PartTree.<init>(PartTree.java:83)
at org.springframework.data.jpa.repository.query.PartTreeJpaQuery.<init>(PartTreeJpaQuery.java:57)
at org.springframework.data.jpa.repository.query.JpaQueryLookupStrategy$CreateQueryLookupStrategy.resolveQuery(JpaQueryLookupStrategy.java:91)
at org.springframework.data.jpa.repository.query.JpaQueryLookupStrategy$CreateIfNotFoundQueryLookupStrategy.resolveQuery(JpaQueryLookupStrategy.java:162)
at org.springframework.data.jpa.repository.query.JpaQueryLookupStrategy$AbstractQueryLookupStrategy.resolveQuery(JpaQueryLookupStrategy.java:69)
at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.<init>(RepositoryFactorySupport.java:304)
at org.springframework.data.repository.core.support.RepositoryFactorySupport.getRepository(RepositoryFactorySupport.java:161)
at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.initAndReturn(RepositoryFactoryBeanSupport.java:224)
at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.afterPropertiesSet(RepositoryFactoryBeanSupport.java:210)
at org.springframework.data.jpa.repository.support.JpaRepositoryFactoryBean.afterPropertiesSet(JpaRepositoryFactoryBean.java:84)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1571)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1509)
... 60 more
原因:org.springframework.beans.factory.beancreatition异常:无法自动连线字段:private com.acinfotech.timebound.jpa.dao.TbiDDCustomQueryConfigDao com.acinfotech.timebound.jpa.service.ReportJobsPersistenceServiceImpl.tbiDDCustomQueryDao;嵌套异常为org.springframework.beans.factory.BeanCreationException:创建名为“tbiDDCustomQueryConfigDao”的bean时出错:调用init方法失败;嵌套异常为org.springframework.data.mapping.PropertyReferenceException:未找到TbiDDCustomQueryConfig类型的属性dd!
位于org.springframework.beans.factory.annotation.AutoWiredNotationBeanPostProcessor$AutoWiredFeldElement.inject(AutoWiredNotationBeanPostProcessor.java:517)
位于org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:87)
位于org.springframework.beans.factory.annotation.AutoWiredNotationBeanPostProcessor.postProcessPropertyValues(AutoWiredNotationBeanPostProcessor.java:286)
... 48多
原因:org.springframework.beans.factory.BeanCreationException:创建名为“tbiDDCustomQueryConfigDao”的bean时出错:调用init方法失败;嵌套异常为org.springframework.data.mapping.PropertyReferenceException:未找到TbiDDCustomQueryConfig类型的属性dd!
位于org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1512)
位于org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:521)
位于org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:458)
位于org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:296)
位于org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223)
位于org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:293)
位于org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
位于org.springframework.beans.factory.support.DefaultListableBeanFactory.FindAuthories(DefaultListableBeanFactory.java:912)
位于org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:855)
位于org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:770)
位于org.springframework.beans.factory.annotation.AutoWiredNotationBeanPostProcessor$AutoWiredFeldElement.inject(AutoWiredNotationBeanPostProcessor.java:489)
... 50多
原因:org.springframework.data.mapping.PropertyReferenceException:未找到TbiDDCustomQueryConfig类型的属性dd!
位于org.springframework.data.mapping.PropertyPath.(PropertyPath.java:75)
位于org.springframework.data.mapping.PropertyPath.create(PropertyPath.java:327)
位于org.springframework.data.mapping.PropertyPath.create(PropertyPath.java:359)
位于org.springframework.data.mapping.PropertyPath.create(PropertyPath.java:359)
位于org.springframework.data.mapping.PropertyPath.create(PropertyPath.java:307)
位于org.springframework.data.mapping.PropertyPath.from(PropertyPath.java:270)
位于org.springframework.data.mapping.PropertyPath.from(PropertyPath.java:241)
位于org.springframework.data.repository.query.parser.Part.(Part.java:76)
位于org.springframework.data.repository.query.parser.PartTree$OrPart.(PartTree.java:201)
位于org.springframework.data.repository.query.parser.PartTree$Predicate.buildTree(PartTree.java:291)
位于org.springframework.data.repository.query.parser.PartTree$Predicate.(PartTree.java:271)
位于org.springframework.data.repository.query.parser.PartTree(PartTree.java:83)
位于org.springframework.data.jpa.repository.query.PartTreeJpaQuery(PartTreeJpaQuery.java:57)
位于org.springframework.data.jpa.repository.query.JpaQueryLookupStrategy$CreateQueryLookupStrategy.resolveQuery(JpaQueryLookupStrategy.java:91)
位于org.springframework.data.jpa.repository.query.JpaQueryLookupStrategy$CreateIfNotFoundQueryLookupStrategy.resolveQuery(JpaQueryLookupStrategy.java:162)
位于org.springframework.data.jpa.repository.query.JpaQueryLookupStrategy$AbstractQueryLookupStrategy.resolveQuery(JpaQueryLookupStrategy.java:69)
位于org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor。(RepositoryFactorySupport.java:304)
位于org.springframework.data.repository.core.support.RepositoryFactorySupport.getRepository(RepositoryFactorySupport.java:161)
位于org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.initAndReturn(RepositoryFactoryBeanSupport.java:224)
位于org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.afterPropertieSet(RepositoryFactoryBeanSupport.java:210)
位于org.springframework.data.jpa.repository.support.JpaRepositoryFactoryBean.AfterPropertieSet(JpaRepositoryFactoryBean.java:84)
位于org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1571)
位于org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1509)
... 60多
不能让具有相同名称的用户使用相同的参数。Java不允许这样。如果重命名由spring数据jpa自动解释的lower方法,它将不起作用。解释未使用@Query
注释的方法
Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.acinfotech.timebound.jpa.dao.TbiDDCustomQueryConfigDao com.acinfotech.timebound.jpa.service.ReportJobsPersistenceServiceImpl.tbiDDCustomQueryDao; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'tbiDDCustomQueryConfigDao': Invocation of init method failed; nested exception is org.springframework.data.mapping.PropertyReferenceException: No property dd found for type TbiDDCustomQueryConfig!
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:517)
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:87)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:286)
... 48 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'tbiDDCustomQueryConfigDao': Invocation of init method failed; nested exception is org.springframework.data.mapping.PropertyReferenceException: No property dd found for type TbiDDCustomQueryConfig!
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1512)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:521)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:458)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:296)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:293)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:912)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:855)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:770)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:489)
... 50 more
Caused by: org.springframework.data.mapping.PropertyReferenceException: No property dd found for type TbiDDCustomQueryConfig!
at org.springframework.data.mapping.PropertyPath.<init>(PropertyPath.java:75)
at org.springframework.data.mapping.PropertyPath.create(PropertyPath.java:327)
at org.springframework.data.mapping.PropertyPath.create(PropertyPath.java:359)
at org.springframework.data.mapping.PropertyPath.create(PropertyPath.java:359)
at org.springframework.data.mapping.PropertyPath.create(PropertyPath.java:307)
at org.springframework.data.mapping.PropertyPath.from(PropertyPath.java:270)
at org.springframework.data.mapping.PropertyPath.from(PropertyPath.java:241)
at org.springframework.data.repository.query.parser.Part.<init>(Part.java:76)
at org.springframework.data.repository.query.parser.PartTree$OrPart.<init>(PartTree.java:201)
at org.springframework.data.repository.query.parser.PartTree$Predicate.buildTree(PartTree.java:291)
at org.springframework.data.repository.query.parser.PartTree$Predicate.<init>(PartTree.java:271)
at org.springframework.data.repository.query.parser.PartTree.<init>(PartTree.java:83)
at org.springframework.data.jpa.repository.query.PartTreeJpaQuery.<init>(PartTreeJpaQuery.java:57)
at org.springframework.data.jpa.repository.query.JpaQueryLookupStrategy$CreateQueryLookupStrategy.resolveQuery(JpaQueryLookupStrategy.java:91)
at org.springframework.data.jpa.repository.query.JpaQueryLookupStrategy$CreateIfNotFoundQueryLookupStrategy.resolveQuery(JpaQueryLookupStrategy.java:162)
at org.springframework.data.jpa.repository.query.JpaQueryLookupStrategy$AbstractQueryLookupStrategy.resolveQuery(JpaQueryLookupStrategy.java:69)
at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.<init>(RepositoryFactorySupport.java:304)
at org.springframework.data.repository.core.support.RepositoryFactorySupport.getRepository(RepositoryFactorySupport.java:161)
at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.initAndReturn(RepositoryFactoryBeanSupport.java:224)
at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.afterPropertiesSet(RepositoryFactoryBeanSupport.java:210)
at org.springframework.data.jpa.repository.support.JpaRepositoryFactoryBean.afterPropertiesSet(JpaRepositoryFactoryBean.java:84)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1571)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1509)
... 60 more
findByDdConfigIdAndIsActive (Integer ddConfigId,String isActive);
findByParentGroupIdIsNullAndDeleted(boolean deleted); //parentGroupId , deleted