Mybatis报错 Error querying database. Cause: org.apache.ibatis.reflection.ReflectionException: Error instantiating class com.me.mybatis.pojo.Orders with invalid types () or values ().

在学mybaits的时候遇到了这个错误,而且卡住了我三个小时也找不到,最后分析出来不能初始化类,然后就结合着之前自己以前的一点经验发现只有有参构造没有无参构造,因此只需要添加上无参构造就可以了。

错误源码

org.apache.ibatis.exceptions.PersistenceException:
### Error querying database.  Cause: org.apache.ibatis.reflection.ReflectionException: Error instantiating class com.me.mybatis.pojo.Orders with invalid types () or values (). Cause: java.lang.NoSuchMethodException: com.me.mybatis.pojo.Orders.<init>()
### The error may exist in SqlMap/Order.xml
### The error may involve defaultParameterMap
### The error occurred while setting parameters
### SQL: select * from orders
### Cause: org.apache.ibatis.reflection.ReflectionException: Error instantiating class com.me.mybatis.pojo.Orders with invalid types () or values (). Cause: java.lang.NoSuchMethodException: com.me.mybatis.pojo.Orders.<init>()
 at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:26)
 at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:111)
 at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:102)
 at org.apache.ibatis.binding.MapperMethod.executeForMany(MapperMethod.java:119)
 at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:63)
 at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:52)
 at com.sun.proxy.$Proxy10.findAllOrders(Unknown Source)
 at com.me.mybatis.junit.MybatisMapperTest.testFindAllOrders(MybatisMapperTest.java:88)
 at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
 at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
 at java.base/java.lang.reflect.Method.invoke(Method.java:567)
 at org.junit.platform.commons.util.ReflectionUtils.invokeMethod(ReflectionUtils.java:628)
 at org.junit.jupiter.engine.execution.ExecutableInvoker.invoke(ExecutableInvoker.java:117)
 at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.lambda$invokeTestMethod$7(TestMethodTestDescriptor.java:184)
 at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
 at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.invokeTestMethod(TestMethodTestDescriptor.java:180)
 at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.execute(TestMethodTestDescriptor.java:127)
 at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.execute(TestMethodTestDescriptor.java:68)
 at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$5(NodeTestTask.java:135)
 at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
 at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$7(NodeTestTask.java:125)
 at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:135)
 at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:123)
 at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
 at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:122)
 at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:80)
 at java.base/java.util.ArrayList.forEach(ArrayList.java:1540)
 at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:38)
 at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$5(NodeTestTask.java:139)
 at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
 at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$7(NodeTestTask.java:125)
 at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:135)
 at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:123)
 at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
 at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:122)
 at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:80)
 at java.base/java.util.ArrayList.forEach(ArrayList.java:1540)
 at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:38)
 at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$5(NodeTestTask.java:139)
 at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
 at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$7(NodeTestTask.java:125)
 at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:135)
 at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:123)
 at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
 at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:122)
 at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:80)
 at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.submit(SameThreadHierarchicalTestExecutorService.java:32)
 at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor.execute(HierarchicalTestExecutor.java:57)
 at org.junit.platform.engine.support.hierarchical.HierarchicalTestEngine.execute(HierarchicalTestEngine.java:51)
 at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:229)
 at org.junit.platform.launcher.core.DefaultLauncher.lambda$execute$6(DefaultLauncher.java:197)
 at org.junit.platform.launcher.core.DefaultLauncher.withInterceptedStreams(DefaultLauncher.java:211)
 at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:191)
 at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:137)
 at org.eclipse.jdt.internal.junit5.runner.JUnit5TestReference.run(JUnit5TestReference.java:89)
 at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:41)
 at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:541)
 at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:763)
 at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:463)
 at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:209)
Caused by: org.apache.ibatis.reflection.ReflectionException: Error instantiating class com.me.mybatis.pojo.Orders with invalid types () or values (). Cause: java.lang.NoSuchMethodException: com.me.mybatis.pojo.Orders.<init>()
 at org.apache.ibatis.reflection.factory.DefaultObjectFactory.instantiateClass(DefaultObjectFactory.java:86)
 at org.apache.ibatis.reflection.factory.DefaultObjectFactory.create(DefaultObjectFactory.java:48)
 at org.apache.ibatis.reflection.factory.DefaultObjectFactory.create(DefaultObjectFactory.java:41)
 at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.createResultObject(DefaultResultSetHandler.java:528)
 at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.createResultObject(DefaultResultSetHandler.java:507)
 at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.getRowValue(DefaultResultSetHandler.java:331)
 at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.handleRowValuesForSimpleResultMap(DefaultResultSetHandler.java:291)
 at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.handleRowValues(DefaultResultSetHandler.java:266)
 at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.handleResultSet(DefaultResultSetHandler.java:236)
 at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.handleResultSets(DefaultResultSetHandler.java:150)
 at org.apache.ibatis.executor.statement.PreparedStatementHandler.query(PreparedStatementHandler.java:60)
 at org.apache.ibatis.executor.statement.RoutingStatementHandler.query(RoutingStatementHandler.java:73)
 at org.apache.ibatis.executor.SimpleExecutor.doQuery(SimpleExecutor.java:60)
 at org.apache.ibatis.executor.BaseExecutor.queryFromDatabase(BaseExecutor.java:267)
 at org.apache.ibatis.executor.BaseExecutor.query(BaseExecutor.java:137)
 at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:96)
 at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:77)
 at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:108)
 ... 59 more
Caused by: java.lang.NoSuchMethodException: com.me.mybatis.pojo.Orders.<init>()
 at java.base/java.lang.Class.getConstructor0(Class.java:3355)
 at java.base/java.lang.Class.getDeclaredConstructor(Class.java:2559)
 at org.apache.ibatis.reflection.factory.DefaultObjectFactory.instantiateClass(DefaultObjectFactory.java:60)
 ... 76 more

原文地址:https://www.cnblogs.com/tkg1314/p/12283827.html

时间: 2024-10-14 14:39:51

Mybatis报错 Error querying database. Cause: org.apache.ibatis.reflection.ReflectionException: Error instantiating class com.me.mybatis.pojo.Orders with invalid types () or values ().的相关文章

Error querying database. Cause: org.apache.ibatis.reflection.ReflectionException: There is no getter for property named &#39;ItemsCustom&#39; in &#39;class com.pojo.OrderDetailCustom

再用 junit 测试MyBatis时发现的错误: org.apache.ibatis.exceptions.PersistenceException: ### Error querying database.  Cause: org.apache.ibatis.reflection.ReflectionException: There is no getter for property named 'ItemsCustom' in 'class com.pojo.OrderDetailCust

mybatis Caused by: org.apache.ibatis.reflection.ReflectionException: Error instantiating class .. with invalid types () or values (). Cause: java.lang.NoSuchMethodException: ...&lt;init&gt;()

此类错误需要在无参构造器中调用父类 public Test(){ super(); }

mybatis之org.apache.ibatis.reflection.ReflectionException: There is no getter for property named &#39;time&#39; in &#39;class java.lang.String&#39;

mybatis接口 List<String> getUsedCate(String time); 配置文件 <select id="getUsedCate" parameterType="java.lang.String" resultType="java.lang.String"> select distinct(cate.cate_name) from account as acc left join conCateg

SpringMvc错误:HTTP Status 500 - Request processing failed; nested exception is org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.reflection.ReflectionException: There is n

HTTP Status 500 - Request processing failed; nested exception is org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.reflection.ReflectionException: There is no getter for property named 'ItemsCustom' in 'class com.mybati

MyBatis笔记----报错Exception in thread &quot;main&quot; org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.ij34.model.UserMapper.selectUser

信息: Refreshing org[email protected]41cf53f9: startup date [Wed Apr 05 16:48:12 CST 2017]; root of context hierarchy 四月 05, 2017 4:48:12 下午 org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions 信息: Loading XML bean definiti

【报错】java.lang.ClassNotFoundException: org.apache.ibatis.session.SqlSession

报错 java.lang.ClassNotFoundException: org.apache.ibatis.session.SqlSession 或者 java.lang.ClassNotFoundException: org.mybatis.spring.SqlSessionFactoryBean 很明显  都是因为类找不到:SqlSession 这个类或者 SqlSessionFactoryBean找不到 解决方法: 整合ssm时忘记加上mybatis依赖以及mybatis-spring

mybatis报错 Error instantiating interface com.atguigu.mybatis.dao.DepartmentMapper with invalid types () or values ()

错因在于把 <association property="dept" select="com.atguigu.mybatis.dao.DepartmentMapper.getDeptById" column="d_id"> </association> 写成了 <association property="dept" javaType="com.atguigu.mybatis.dao.D

使用mybatis报错constructor found in com.atguigu.mybatis.bean.Department matching [java.lang.Integer, java.lang.String]

报错constructor found in com.atguigu.mybatis.bean.Department matching [java.lang.Integer, java.lang.String] 构造方法不匹配,因为反射中会使用默认的无参构造器,而当我们一旦写了新的带参构造方法,那么就不会存在无参构造方法了,需要重新写过.自己在相应的实体中写一个无参构造方法就可以了. 完整报错如下所示: org.apache.ibatis.exceptions.PersistenceExcept

mybatis报错invalid types () or values ()解决方法

### Cause: org.apache.ibatis.reflection.ReflectionException: Error instantiating class com.chry.browserServer.db.model.User with invalid types () or values (). ause: java.lang.NoSuchMethodException: com.chry.browserServer.db.model.User.<init>()] wit