spring data jpa 问题,关于实现接口方面的

问题描述

1、这个是jpa配置,其中配置了repository-impl-postfix="Impl"这一项。<jpa:repositoriesbase-package="com.nk"repository-impl-postfix="Impl"entity-manager-factory-ref="entityManagerFactory"transaction-manager-ref="transactionManager"></jpa:repositories>

2、接口publicinterfacePermissionDaoextendsPagingAndSortingRepository<Permission,Integer>{/*方法的实现由PermissionDaoImpl完成*/List<Permission>findByEmployeeId(IntegeremployeeId);}

3、实现,由于sql比较复杂,由mybatis实现。publicclassPermissionDAOImplextendsBaseDaoImpl<Permission>{publicPermissionDAOImpl(){super(Permission.class);}/*实现的是接口中的方法*/publicList<Permission>findByEmployeeId(IntegeremployeeId){Map<String,Object>params=newHashMap<String,Object>();params.put("employeeId",employeeId);returnsuper.sqlSession.selectList(super.entityMapper+"findByEmployeeId",employeeId);}}

结果:项目启动时报错:Causedby:org.springframework.beans.factory.BeanCreationException:Errorcreatingbeanwithname'permissionDao':FactoryBeanthrewexceptiononobjectcreation;nestedexceptionisjava.lang.IllegalArgumentException:Couldnotcreatequerymetamodelformethodpublicabstractjava.util.Listcom.nk.emis.basedata.dao.PermissionDao.findByEmployeeId(java.lang.Integer)!atorg.springframework.beans.factory.support.FactoryBeanRegistrySupport.doGetObjectFromFactoryBean(FactoryBeanRegistrySupport.java:149)atorg.springframework.beans.factory.support.FactoryBeanRegistrySupport.getObjectFromFactoryBean(FactoryBeanRegistrySupport.java:102)atorg.springframework.beans.factory.support.AbstractBeanFactory.getObjectForBeanInstance(AbstractBeanFactory.java:1442)atorg.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:305)atorg.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)atorg.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:848)atorg.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:790)atorg.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:707)atorg.springframework.context.annotation.CommonAnnotationBeanPostProcessor.autowireResource(CommonAnnotationBeanPostProcessor.java:438)atorg.springframework.context.annotation.CommonAnnotationBeanPostProcessor.getResource(CommonAnnotationBeanPostProcessor.java:416)atorg.springframework.context.annotation.CommonAnnotationBeanPostProcessor$ResourceElement.getResourceToInject(CommonAnnotationBeanPostProcessor.java:549)atorg.springframework.beans.factory.annotation.InjectionMetadata$InjectedElement.inject(InjectionMetadata.java:150)atorg.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:87)atorg.springframework.context.annotation.CommonAnnotationBeanPostProcessor.postProcessPropertyValues(CommonAnnotationBeanPostProcessor.java:303)...43moreCausedby:java.lang.IllegalArgumentException:Couldnotcreatequerymetamodelformethodpublicabstractjava.util.Listcom.nk.emis.basedata.dao.PermissionDao.findByEmployeeId(java.lang.Integer)!atorg.springframework.data.jpa.repository.query.JpaQueryLookupStrategy$CreateQueryLookupStrategy.resolveQuery(JpaQueryLookupStrategy.java:95)atorg.springframework.data.jpa.repository.query.JpaQueryLookupStrategy$CreateIfNotFoundQueryLookupStrategy.resolveQuery(JpaQueryLookupStrategy.java:164)atorg.springframework.data.jpa.repository.query.JpaQueryLookupStrategy$AbstractQueryLookupStrategy.resolveQuery(JpaQueryLookupStrategy.java:71)atorg.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.<init>(RepositoryFactorySupport.java:303)atorg.springframework.data.repository.core.support.RepositoryFactorySupport.getRepository(RepositoryFactorySupport.java:157)atorg.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.getObject(RepositoryFactoryBeanSupport.java:120)atorg.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.getObject(RepositoryFactoryBeanSupport.java:39)atorg.springframework.beans.factory.support.FactoryBeanRegistrySupport.doGetObjectFromFactoryBean(FactoryBeanRegistrySupport.java:142)...56moreCausedby:java.lang.IllegalArgumentException:Nopropertyemployeefoundfortypeclasscom.nk.emis.basedata.entity.Permissionatorg.springframework.data.repository.query.parser.Property.<init>(Property.java:76)atorg.springframework.data.repository.query.parser.Property.<init>(Property.java:97)atorg.springframework.data.repository.query.parser.Property.create(Property.java:312)atorg.springframework.data.repository.query.parser.Property.create(Property.java:326)atorg.springframework.data.repository.query.parser.Property.create(Property.java:292)atorg.springframework.data.repository.query.parser.Property.from(Property.java:251)atorg.springframework.data.repository.query.parser.Property.from(Property.java:232)atorg.springframework.data.repository.query.parser.Part.<init>(Part.java:48)atorg.springframework.data.repository.query.parser.PartTree$OrPart.<init>(PartTree.java:242)atorg.springframework.data.repository.query.parser.PartTree.buildTree(PartTree.java:101)atorg.springframework.data.repository.query.parser.PartTree.<init>(PartTree.java:77)atorg.springframework.data.jpa.repository.query.PartTreeJpaQuery.<init>(PartTreeJpaQuery.java:56)atorg.springframework.data.jpa.repository.query.JpaQueryLookupStrategy$CreateQueryLookupStrategy.resolveQuery(JpaQueryLookupStrategy.java:93)...63more

说是我的Permission实体中没有那个属性,我的实体中确实没有,可是我由impl实现的。现在我想用impl去实现这个方法,该怎么处理?

解决方案

解决方案二:
完整异常严重:Exceptionsendingcontextinitializedeventtolistenerinstanceofclassorg.springframework.web.context.ContextLoaderListenerorg.springframework.beans.factory.BeanCreationException:Errorcreatingbeanwithname'permissionServiceImpl':Injectionofresourcedependenciesfailed;nestedexceptionisorg.springframework.beans.factory.BeanCreationException:Errorcreatingbeanwithname'permissionDao':FactoryBeanthrewexceptiononobjectcreation;nestedexceptionisjava.lang.IllegalArgumentException:Couldnotcreatequerymetamodelformethodpublicabstractjava.util.Listcom.nk.emis.basedata.dao.PermissionDao.findByEmployeeId(java.lang.Integer)!atorg.springframework.context.annotation.CommonAnnotationBeanPostProcessor.postProcessPropertyValues(CommonAnnotationBeanPostProcessor.java:306)atorg.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1106)atorg.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517)atorg.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)atorg.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294)atorg.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225)atorg.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291)atorg.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)atorg.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:585)atorg.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:913)atorg.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:464)atorg.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:385)atorg.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:284)atorg.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:111)atorg.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4135)atorg.apache.catalina.core.StandardContext.start(StandardContext.java:4630)atorg.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)atorg.apache.catalina.core.StandardHost.start(StandardHost.java:785)atorg.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)atorg.apache.catalina.core.StandardEngine.start(StandardEngine.java:445)atorg.apache.catalina.startup.Embedded.start(Embedded.java:825)atorg.codehaus.mojo.tomcat.AbstractRunMojo.startContainer(AbstractRunMojo.java:558)atorg.codehaus.mojo.tomcat.AbstractRunMojo.execute(AbstractRunMojo.java:255)atorg.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:101)atorg.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:209)atorg.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)atorg.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)atorg.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84)atorg.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59)atorg.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183)atorg.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161)atorg.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:320)atorg.apache.maven.DefaultMaven.execute(DefaultMaven.java:156)atorg.apache.maven.cli.MavenCli.execute(MavenCli.java:537)atorg.apache.maven.cli.MavenCli.doMain(MavenCli.java:196)atorg.apache.maven.cli.MavenCli.main(MavenCli.java:141)atsun.reflect.NativeMethodAccessorImpl.invoke0(NativeMethod)atsun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)atsun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)atjava.lang.reflect.Method.invoke(Method.java:597)atorg.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:290)atorg.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:230)atorg.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:409)atorg.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:352)Causedby:org.springframework.beans.factory.BeanCreationException:Errorcreatingbeanwithname'permissionDao':FactoryBeanthrewexceptiononobjectcreation;nestedexceptionisjava.lang.IllegalArgumentException:Couldnotcreatequerymetamodelformethodpublicabstractjava.util.Listcom.nk.emis.basedata.dao.PermissionDao.findByEmployeeId(java.lang.Integer)!atorg.springframework.beans.factory.support.FactoryBeanRegistrySupport.doGetObjectFromFactoryBean(FactoryBeanRegistrySupport.java:149)atorg.springframework.beans.factory.support.FactoryBeanRegistrySupport.getObjectFromFactoryBean(FactoryBeanRegistrySupport.java:102)atorg.springframework.beans.factory.support.AbstractBeanFactory.getObjectForBeanInstance(AbstractBeanFactory.java:1442)atorg.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:305)atorg.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)atorg.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:848)atorg.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:790)atorg.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:707)atorg.springframework.context.annotation.CommonAnnotationBeanPostProcessor.autowireResource(CommonAnnotationBeanPostProcessor.java:438)atorg.springframework.context.annotation.CommonAnnotationBeanPostProcessor.getResource(CommonAnnotationBeanPostProcessor.java:416)atorg.springframework.context.annotation.CommonAnnotationBeanPostProcessor$ResourceElement.getResourceToInject(CommonAnnotationBeanPostProcessor.java:549)atorg.springframework.beans.factory.annotation.InjectionMetadata$InjectedElement.inject(InjectionMetadata.java:150)atorg.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:87)atorg.springframework.context.annotation.CommonAnnotationBeanPostProcessor.postProcessPropertyValues(CommonAnnotationBeanPostProcessor.java:303)...43moreCausedby:java.lang.IllegalArgumentException:Couldnotcreatequerymetamodelformethodpublicabstractjava.util.Listcom.nk.emis.basedata.dao.PermissionDao.findByEmployeeId(java.lang.Integer)!atorg.springframework.data.jpa.repository.query.JpaQueryLookupStrategy$CreateQueryLookupStrategy.resolveQuery(JpaQueryLookupStrategy.java:95)atorg.springframework.data.jpa.repository.query.JpaQueryLookupStrategy$CreateIfNotFoundQueryLookupStrategy.resolveQuery(JpaQueryLookupStrategy.java:164)atorg.springframework.data.jpa.repository.query.JpaQueryLookupStrategy$AbstractQueryLookupStrategy.resolveQuery(JpaQueryLookupStrategy.java:71)atorg.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.<init>(RepositoryFactorySupport.java:303)atorg.springframework.data.repository.core.support.RepositoryFactorySupport.getRepository(RepositoryFactorySupport.java:157)atorg.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.getObject(RepositoryFactoryBeanSupport.java:120)atorg.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.getObject(RepositoryFactoryBeanSupport.java:39)atorg.springframework.beans.factory.support.FactoryBeanRegistrySupport.doGetObjectFromFactoryBean(FactoryBeanRegistrySupport.java:142)...56moreCausedby:java.lang.IllegalArgumentException:Nopropertyemployeefoundfortypeclasscom.nk.emis.basedata.entity.Permissionatorg.springframework.data.repository.query.parser.Property.<init>(Property.java:76)atorg.springframework.data.repository.query.parser.Property.<init>(Property.java:97)atorg.springframework.data.repository.query.parser.Property.create(Property.java:312)atorg.springframework.data.repository.query.parser.Property.create(Property.java:326)atorg.springframework.data.repository.query.parser.Property.create(Property.java:292)atorg.springframework.data.repository.query.parser.Property.from(Property.java:251)atorg.springframework.data.repository.query.parser.Property.from(Property.java:232)atorg.springframework.data.repository.query.parser.Part.<init>(Part.java:48)atorg.springframework.data.repository.query.parser.PartTree$OrPart.<init>(PartTree.java:242)atorg.springframework.data.repository.query.parser.PartTree.buildTree(PartTree.java:101)atorg.springframework.data.repository.query.parser.PartTree.<init>(PartTree.java:77)atorg.springframework.data.jpa.repository.query.PartTreeJpaQuery.<init>(PartTreeJpaQuery.java:56)atorg.springframework.data.jpa.repository.query.JpaQueryLookupStrategy$CreateQueryLookupStrategy.resolveQuery(JpaQueryLookupStrategy.java:93)...63more

解决方案三:
publicclassMyRepositoryImpl<T,IDextendsSerializable>extendsSimpleJpaRepository<T,ID>implementsMyRepository<T,ID>{privateEntityManagerentityManager;//Therearetwoconstructorstochoosefrom,eithercanbeused.publicMyRepositoryImpl(Class<T>domainClass,EntityManagerentityManager){super(domainClass,entityManager);//Thisistherecommendedmethodforaccessinginheritedclassdependencies.this.entityManager=entityManager;}publicvoidsharedCustomMethod(IDid){//implementationgoeshere}}

建议从Simple类继承实现类

时间: 2024-11-08 19:57:12

spring data jpa 问题,关于实现接口方面的的相关文章

java spring data jpa 对page pageable接口的实现

问题描述 javaspringdatajpa是否已经对pagepageable接口进行了实现,如果有我该怎么进入源码.还有如下的代码intpage=1;intpageSize=5;Pageablepageable=newPageRequest(page,pageSize);Page<CourseRequest>allCourseRequest=courseRequestDao.findAll(pageable);1.我怎么这个时候从数据库得到的allCourseRequest对象context

Spring Data JPA方法定义规范【从零开始学Spring Boot】

视频&交流平台] à SpringBoot网易云课堂视频 http://study.163.com/course/introduction.htm?courseId=1004329008 à Spring Boot交流平台 http://412887952-qq-com.iteye.com/blog/2321532           事情的起因:有人问过我们这个这个问题:为什么我利用Spring data jpa写的方法没有按照我想要的情况进行执行呢?我记得当时只是告诉他你你先看看Spring

spring data jpa的误将方法名当成属性名称的问题

问题描述 项目中使用了spring data jpa,自己扩展了一个全局接口AbstractJxetRepositorypublic interface AbstractJxetRepository<T> {public void batchInster(List<T> list, int size) throws Exception;public void batchUpdate(List<T> list, int size) throws Exception;}实现

Spring Boot 整合 Spring Data Jpa

配置spring data jpa 及 整合 druid数据库连接池 添加数据库驱动依赖和spring data jpa 依赖 我们使用的是mysql数据库,还需要添加的数据库驱动依赖是mysql-connector-java <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLoc

springboot(五):spring data jpa的使用

在上篇文章springboot(二):web综合开发中简单介绍了一下spring data jpa的基础性使用,这篇文章将更加全面的介绍spring data jpa 常见用法以及注意事项 使用spring data jpa 开发时,发现国内对spring boot jpa全面介绍的文章比较少案例也比较零碎,因此写文章总结一下.本人也正在翻译Spring Data JPA 参考指南,有兴趣的同学欢迎联系我,一起加入翻译中! spring data jpa介绍 首先了解JPA是什么? JPA(Ja

spring data jpa 的一些疑问

问题描述 http://www.ibm.com/developerworks/cn/opensource/os-cn-spring-jpa/<使用 Spring Data JPA 简化 JPA 开发>这篇文章相信大家一定拜读过 但是这2天我在继续试用spring data jpa中遇到了不少挫折. 首先遇到的是原文中写到"默认情况下,Spring Data JPA 实现的方法都是使用事务的.针对查询类型的方法,其等价于 @Transactional(readOnly=true):增删

在使用Spring Data JPA时发现的问题

问题描述 在实际应用中,我们通常会在页面上进行组合查询,例如用户这个对象 页面上会列出用户姓名.年龄.学历.性别.地址.电话等等的一系列查询条件 最近在学习Spring Data JPA,不知这个怎么实现这种组合条件的查询啊 只能手动判断后写SQL吗 解决方案 自行扩展接口实现或者参考以下帖子http://stackoverflow.com/questions/2880209/jpa-findbyexample解决方案二:springdata代码下载:http://www.zuidaima.co

8.3. Spring Data JPA

8.3.1. @Entity 8.3.1.1. @Id ID 字段 @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = "id", unique = true, nullable = false, insertable = true, updatable = false) private int id; 8.3.1.2. @Table 8.3.1.2.1. catalog @Table(name=

spring boot(五):spring data jpa的使用

在上篇文章springboot(二):web综合开发中简单介绍了一下spring data jpa的基础性使用,这篇文章将更加全面的介绍spring data jpa 常见用法以及注意事项 使用spring data jpa 开发时,发现国内对spring boot jpa全面介绍的文章比较少案例也比较零碎,因此写文章总结一下.本人也正在翻译Spring Data JPA 参考指南,有兴趣的同学欢迎联系我,一起加入翻译中! spring data jpa介绍 首先了解JPA是什么? JPA(Ja

5.3. Spring Data JPA

5.3.1. @Entity 5.3.1.1. @Id ID 字段 @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = "id", unique = true, nullable = false, insertable = true, updatable = false) private int id; 5.3.1.2. @Table 5.3.1.2.1. catalog @Table(name=