Mybatis出现的错误

版权声明:本文为博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/qq_41971087/article/details/82011964

在使用Mybatis持久层框架进行操作数据库的时候,出现了以下的问题:

严重:  

严重:Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'logContrller': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: com.youquan.service.LogService com.youquan.mvc.LogContrller.logService; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'logServiceImpl': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: com.youquan.dao.LogDao com.youquan.service.LogServiceImpl.logDao; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.youquan.dao.LogDao] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}

一直没有看懂是哪里的问题,问了朋友说是xml映射错误,后来自己仔细的看了下错误,发现了一个问题:

 Error resolving class. Cause: org.apache.ibatis.type.TypeException: Could not resolve type alias 'LogResult'.  Cause: java.lang.ClassNotFoundException: Cannot find class: LogResult

这个就是错误的根源所在,是这个类型不能返回,找那个文件中定义了这个 LogResult,在我的xml映射文件中找到了:

<mapper namespace="com.youquan.dao.LogDao">
    <resultMap id="LogResult" type="com.youquan.bean.Log" autoMapping="false" >
        <id property="id" column="id" /><!--主键-->
        <result property="uid" column="uid" />
        <result property="createTime" column="createTime" />
        <result property="ip" column="ip" />
    </resultMap>
    <select id="findAll" resultType="LogResult">
        SELECT * FROM log;
    </select>

这里我们看到问题在 查询语句中的resultType="LogResult"这里我们返回了一个由<resultMap>定义的结果集这个是错误的问题所在,解决: 把resultType改成resultMap, 或者把LogResult这个换成实体类,或别名

这里作者就去查看了resultType与resultMap的区别:

restulyType:

对应的是java对象中的属性,大小写不敏感,

如果放的是java.lang.Map,key是查询语句的列名,value是查询的值,大小写敏感

resultMap:

指的是定义好了的id的,是定义好的resyltType的引用

注意:用resultType的时候,要保证结果集的列名与java对象的属性相同,而resultMap则不用,而且resultMap可以用typeHander转换

type:java 对象对应的类,id:在本文件要唯一column :数据库的列名或别名,property:对应java对象的属性,jdbcType:java.sql.Types

查询语句中,resultMap属性指向上面那个属性的标签的id, parameterType:参数类型,只能传一个参数,如果有多个参数要封装,如封装成一个类,要写包名加类名,基本数据类型则可以省略一对1、一对多时,若有表的字段相同必须写别名,不然查询结果无法正常映射,出现某属性为空或者返回的结果与想象中的不同,而这往往是没有报错的。

若有意外中的错误,反复检查以上几点,和认真核查自己的sql语句,mapper.xml文件是否配置正确。

简单来说就是resultType不能返回由resultMap的结果集,

resultMap只能使用由resultMap的结果集

 

更详细的resultType与resultMap的区别请看https://blog.csdn.net/leo3070/article/details/77899574/

展开阅读全文

Mybatis整合出现错误

09-07

九月 07, 2017 5:28:58 下午 org.springframework.context.support.GenericApplicationContext refreshrn警告: Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlSessionFactory' defined in class path resource [applicationContext.xml]: Invocation of init method failed; nested exception is org.springframework.core.NestedIOException: Failed to parse mapping resource: 'file [F:\javaWorkSpace\ssm-crud\target\classes\mapper\DepartmentMapper.xml]'; nested exception is org.apache.ibatis.builder.BuilderException: Error parsing Mapper XML. Cause: java.lang.IllegalArgumentException: Result Maps collection already contains value for com.atguigu.crud.dao.DepartmentMapper.BaseResultMaprn九月 07, 2017 5:28:58 下午 org.springframework.test.context.TestContextManager prepareTestInstancern严重: Caught exception while allowing TestExecutionListener [org.springframework.test.context.support.DependencyInjectionTestExecutionListener@30c7da1e] to prepare test instance [com.atguigu.crud.test.MapperTest@4681c175]rnjava.lang.IllegalStateException: Failed to load ApplicationContextrn at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:124)rn at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:83)rn at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.injectDependencies(DependencyInjectionTestExecutionListener.java:117)rn at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.prepareTestInstance(DependencyInjectionTestExecutionListener.java:83)rn at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:230)rn at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTest(SpringJUnit4ClassRunner.java:228)rn at org.springframework.test.context.junit4.SpringJUnit4ClassRunner$1.runReflectiveCall(SpringJUnit4ClassRunner.java:287)rn at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)rn at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.methodBlock(SpringJUnit4ClassRunner.java:289)rn at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:247)rn at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:94)rn at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)rn at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)rn at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)rn at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)rn at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)rn at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)rn at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)rn at org.junit.runners.ParentRunner.run(ParentRunner.java:363)rn at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:191)rn at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)rn at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)rn at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)rn at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:678)rn at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)rn at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)rnCaused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlSessionFactory' defined in class path resource [applicationContext.xml]: Invocation of init method failed; nested exception is org.springframework.core.NestedIOException: Failed to parse mapping resource: 'file [F:\javaWorkSpace\ssm-crud\target\classes\mapper\DepartmentMapper.xml]'; nested exception is org.apache.ibatis.builder.BuilderException: Error parsing Mapper XML. Cause: java.lang.IllegalArgumentException: Result Maps collection already contains value for com.atguigu.crud.dao.DepartmentMapper.BaseResultMaprn at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1628)rn at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:555)rn at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483)rn at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)rn at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)rn at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)rn at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)rn at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:742)rn at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:866)rn at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:542)rn at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:128)rn at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:60)rn at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.delegateLoading(AbstractDelegatingSmartContextLoader.java:108)rn at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.loadContext(AbstractDelegatingSmartContextLoader.java:251)rn at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:98)rn at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:116)rn ... 25 morernCaused by: org.springframework.core.NestedIOException: Failed to parse mapping resource: 'file [F:\javaWorkSpace\ssm-crud\target\classes\mapper\DepartmentMapper.xml]'; nested exception is org.apache.ibatis.builder.BuilderException: Error parsing Mapper XML. Cause: java.lang.IllegalArgumentException: Result Maps collection already contains value for com.atguigu.crud.dao.DepartmentMapper.BaseResultMaprn at org.mybatis.spring.SqlSessionFactoryBean.buildSqlSessionFactory(SqlSessionFactoryBean.java:523)rn at org.mybatis.spring.SqlSessionFactoryBean.afterPropertiesSet(SqlSessionFactoryBean.java:380)rn at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1687)rn at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1624)rn ... 40 morernCaused by: org.apache.ibatis.builder.BuilderException: Error parsing Mapper XML. Cause: java.lang.IllegalArgumentException: Result Maps collection already contains value for com.atguigu.crud.dao.DepartmentMapper.BaseResultMaprn at org.apache.ibatis.builder.xml.XMLMapperBuilder.configurationElement(XMLMapperBuilder.java:120)rn at org.apache.ibatis.builder.xml.XMLMapperBuilder.parse(XMLMapperBuilder.java:92)rn at org.mybatis.spring.SqlSessionFactoryBean.buildSqlSessionFactory(SqlSessionFactoryBean.java:521)rn ... 43 morernCaused by: java.lang.IllegalArgumentException: Result Maps collection already contains value for com.atguigu.crud.dao.DepartmentMapper.BaseResultMaprn at org.apache.ibatis.session.Configuration$StrictMap.put(Configuration.java:859)rn at org.apache.ibatis.session.Configuration$StrictMap.put(Configuration.java:831)rn at org.apache.ibatis.session.Configuration.addResultMap(Configuration.java:613)rn at org.apache.ibatis.builder.MapperBuilderAssistant.addResultMap(MapperBuilderAssistant.java:214)rn at org.apache.ibatis.builder.ResultMapResolver.resolve(ResultMapResolver.java:47)rn at org.apache.ibatis.builder.xml.XMLMapperBuilder.resultMapElement(XMLMapperBuilder.java:285)rn at org.apache.ibatis.builder.xml.XMLMapperBuilder.resultMapElement(XMLMapperBuilder.java:252)rn at org.apache.ibatis.builder.xml.XMLMapperBuilder.resultMapElements(XMLMapperBuilder.java:244)rn at org.apache.ibatis.builder.xml.XMLMapperBuilder.configurationElement(XMLMapperBuilder.java:116)rn ... 45 morernrnDepartmentMapper.xml文件是自动生成的,下面是Mybatis的整合。rnrn rn rn rn rnMybatis配置文件没有定义mapperrnrn rn rn rn rn rn rn rn rnrn找了好久找不出来问题,大牛们看下,谢谢rn 论坛

spring 与mybatis 整合出现错误

01-16

一月 16, 2017 10:57:49 上午 org.apache.catalina.core.StandardContext listenerStartrn严重: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListenerrnorg.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlSessionFactory' defined in class path resource [config/spring-mybatis.xml]: Initialization of bean failed; nested exception is org.springframework.beans.TypeMismatchException: Failed to convert property value of type [java.lang.String] to required type [org.springframework.core.io.Resource[]] for property 'mapperLocations'; nested exception is java.lang.IllegalArgumentException: Could not resolve resource location pattern [classpath:fjnu/mapper/*.xml]: class path resource [fjnu/mapper/] cannot be resolved to URL because it does not existrn at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:553)rn at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)rn at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)rn at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)rn at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)rn at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)rn at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:732)rn at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:861)rn at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:541)rn at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:444)rn at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:326)rn at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:107)rn at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4842)rn at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5303)rn at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:147)rn at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1407)rn at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1397)rn at java.util.concurrent.FutureTask.run(Unknown Source)rn at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)rn at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)rn at java.lang.Thread.run(Unknown Source)rnCaused by: org.springframework.beans.TypeMismatchException: Failed to convert property value of type [java.lang.String] to required type [org.springframework.core.io.Resource[]] for property 'mapperLocations'; nested exception is java.lang.IllegalArgumentException: Could not resolve resource location pattern [classpath:fjnu/mapper/*.xml]: class path resource [fjnu/mapper/] cannot be resolved to URL because it does not existrn at org.springframework.beans.AbstractNestablePropertyAccessor.convertIfNecessary(AbstractNestablePropertyAccessor.java:596)rn at org.springframework.beans.AbstractNestablePropertyAccessor.convertForProperty(AbstractNestablePropertyAccessor.java:603)rn at org.springframework.beans.BeanWrapperImpl.convertForProperty(BeanWrapperImpl.java:216)rn at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.convertForProperty(AbstractAutowireCapableBeanFactory.java:1532)rn at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1491)rn at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1231)rn at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:543)rn ... 20 morernCaused by: java.lang.IllegalArgumentException: Could not resolve resource location pattern [classpath:fjnu/mapper/*.xml]: class path resource [fjnu/mapper/] cannot be resolved to URL because it does not existrn at org.springframework.core.io.support.ResourceArrayPropertyEditor.setAsText(ResourceArrayPropertyEditor.java:116)rn at org.springframework.beans.TypeConverterDelegate.doConvertTextValue(TypeConverterDelegate.java:468)rn at org.springframework.beans.TypeConverterDelegate.doConvertValue(TypeConverterDelegate.java:441)rn at org.springframework.beans.TypeConverterDelegate.convertIfNecessary(TypeConverterDelegate.java:199)rn at org.springframework.beans.AbstractNestablePropertyAccessor.convertIfNecessary(AbstractNestablePropertyAccessor.java:576)rn ... 26 morernrn一月 16, 2017 10:57:49 上午 org.apache.catalina.core.StandardContext startInternalrn严重: One or more listeners failed to start. Full details will be found in the appropriate container log filern一月 16, 2017 10:57:49 上午 org.apache.catalina.core.StandardContext startInternalrn严重: Context [] startup failed due to previous errorsrn一月 16, 2017 10:57:49 上午 org.apache.catalina.core.ApplicationContext logrn信息: Closing Spring root WebApplicationContextrn一月 16, 2017 10:57:49 上午 org.apache.coyote.AbstractProtocol startrn信息: Starting ProtocolHandler ["http-nio-8080"]rn一月 16, 2017 10:57:49 上午 org.apache.coyote.AbstractProtocol startrn信息: Starting ProtocolHandler ["ajp-nio-8009"]rn一月 16, 2017 10:57:49 上午 org.apache.catalina.startup.Catalina startrn信息: Server startup in 5746 msrn各位大神帮忙看看 论坛

mybatis错误求助

07-27

求教各位大神,这个错误怎么解决啊?在网上搜不到解决的办法...rn报错是:Exception in thread "main" org.apache.ibatis.exceptions.PersistenceException: rn### Error building SqlSession.rn### The error may exist in SQL Mapper Configurationrn### Cause: org.apache.ibatis.builder.BuilderException: Error parsing SQL Mapper Configuration. Cause: org.apache.ibatis.datasource.DataSourceException: Unknown DataSource property: jdbc.urlrn at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:26)rn at org.apache.ibatis.session.SqlSessionFactoryBuilder.build(SqlSessionFactoryBuilder.java:54)rn at org.apache.ibatis.session.SqlSessionFactoryBuilder.build(SqlSessionFactoryBuilder.java:38)rn at com.test.TeacherTest.getSqlSessionFactory(TeacherTest.java:24)rn at com.test.TeacherTest.selectTeacerByTid(TeacherTest.java:34)rn at com.test.TeacherTest.main(TeacherTest.java:49)rnCaused by: org.apache.ibatis.builder.BuilderException: Error parsing SQL Mapper Configuration. Cause: org.apache.ibatis.datasource.DataSourceException: Unknown DataSource property: jdbc.urlrn at org.apache.ibatis.builder.xml.XMLConfigBuilder.parseConfiguration(XMLConfigBuilder.java:109)rn at org.apache.ibatis.builder.xml.XMLConfigBuilder.parse(XMLConfigBuilder.java:92)rn at org.apache.ibatis.session.SqlSessionFactoryBuilder.build(SqlSessionFactoryBuilder.java:52)rn ... 4 morernCaused by: org.apache.ibatis.datasource.DataSourceException: Unknown DataSource property: jdbc.urlrn at org.apache.ibatis.datasource.unpooled.UnpooledDataSourceFactory.setProperties(UnpooledDataSourceFactory.java:54)rn at org.apache.ibatis.builder.xml.XMLConfigBuilder.dataSourceElement(XMLConfigBuilder.java:275)rn at org.apache.ibatis.builder.xml.XMLConfigBuilder.environmentsElement(XMLConfigBuilder.java:232)rn at org.apache.ibatis.builder.xml.XMLConfigBuilder.parseConfiguration(XMLConfigBuilder.java:104)rn ... 6 morern这是我的mybatis-config.xml文件配置:rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rnrn数据库名称和用户名密码是没错的,请问问题到底出在什么地方呢?mysql服务也启动了。 论坛

MyBatis中批量更新的错误

08-14

实现 批量删除 在Mybatis中写了这样的一句 语句 rn[code=java]rnrn rn rn UPDATE t_skinrn rn is_delete = 1rn rn WHERErn skin_id = #item.skinIdrn /* WHERE skin_id = #skinId*/rn rn rn[/code]rnrnjava代码部分是这样的rn[code=java]rn @Path("XXXXXXXXX")rn @POSTrnpublic IServiceResponse batchDeletionGameSkinAction(String skinId, @Context HttpServletRequest request) rn JSONObject jsonObject = JSONObject.fromObject(skinId);rn JSONArray jsonArray = JSONArray.fromObject(jsonObject);rn List listArray = (List)rn JSONArray.toCollection(jsonArray, BatchDeletionRequest.class);rn rn Integer result = skinManager.batchDeletionByListID(list);rnrn[/code]rnrnjava代码执行到[code=java]Integer result = skinManager.batchDeletionByListID(list);[/code]这一行是出现rn[code=java]rn==> Preparing: UPDATE t_skin SET is_delete = 1 WHERE skin_id = ? /* WHERE skin_id = ?*/ ; UPDATE t_skin SET is_delete = 1 WHERE skin_id = ? /* WHERE skin_id = ?*/rn[/code]rn[code=java]rnERROR c.m.f.c.s.mapper.JsonThrowableMapper [Logger.java:276] - nested exception is org.apache.ibatis.reflection.ReflectionException: There is no getter for property named '' in 'class java.lang.String'rn[/code]rnSQL语句在编译中运行能够运行 但在这里就会出现这种错误rn我还注意到,这里没有显示传递的参数,是这个List集合死了问题,我的List没有错啊 ,SQL中skin_Id也是varchar类型,如果我的想法是对的,我就不知道怎么修改了 rn还请大家帮帮忙 论坛

mybatis mapper执行错误

06-04

[code=text]rnrn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn[/code]rn代码如下rn[code=java]rn@Service("vmGuestService")rnpublic class VMGuestServiceImp implements VMGuestService rn rn @Autowiredrn private VMGuestMapper vmMapper;rn /*rn * Title: createVMGuestrn * Description: rn * @returnrn * @see com.lining.vmservice.service.VMGuestService#createVMGuest()rn */rn rn rn @Overridern public boolean createVMGuest(VMGuest vmGuest) rn // 下面这行报的错rn vmMapper.insert(vmGuest);rn return true;rn rn rn rn[/code]rnrnrn错误信息如下:rn[code=java]rnSEVERE: Servlet.service() for servlet [liningcloud] in context with path [/liningVMservice] threw exception [Handler processing failed; nested exception is java.lang.AbstractMethodError: com.mysql.jdbc.Connection.isValid(I)Z] with root causernjava.lang.AbstractMethodError: com.mysql.jdbc.Connection.isValid(I)Zrn at org.apache.commons.dbcp2.DelegatingConnection.isValid(DelegatingConnection.java:914)rn at org.apache.commons.dbcp2.PoolableConnection.validate(PoolableConnection.java:227)rn at org.apache.commons.dbcp2.PoolableConnectionFactory.validateConnection(PoolableConnectionFactory.java:303)rn at org.apache.commons.dbcp2.BasicDataSource.validateConnectionFactory(BasicDataSource.java:2165)rn at org.apache.commons.dbcp2.BasicDataSource.createPoolableConnectionFactory(BasicDataSource.java:2148)rn at org.apache.commons.dbcp2.BasicDataSource.createDataSource(BasicDataSource.java:1903)rn at org.apache.commons.dbcp2.BasicDataSource.getConnection(BasicDataSource.java:1413)rn at org.springframework.jdbc.datasource.DataSourceUtils.doGetConnection(DataSourceUtils.java:111)rn at org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:77)rn at org.mybatis.spring.transaction.SpringManagedTransaction.openConnection(SpringManagedTransaction.java:81)rn at org.mybatis.spring.transaction.SpringManagedTransaction.getConnection(SpringManagedTransaction.java:67)rn at org.apache.ibatis.executor.BaseExecutor.getConnection(BaseExecutor.java:279)rn at org.apache.ibatis.executor.SimpleExecutor.prepareStatement(SimpleExecutor.java:69)rn at org.apache.ibatis.executor.SimpleExecutor.doUpdate(SimpleExecutor.java:44)rn at org.apache.ibatis.executor.BaseExecutor.update(BaseExecutor.java:108)rn at org.apache.ibatis.executor.CachingExecutor.update(CachingExecutor.java:67)rn at org.apache.ibatis.session.defaults.DefaultSqlSession.update(DefaultSqlSession.java:145)rn at org.apache.ibatis.session.defaults.DefaultSqlSession.insert(DefaultSqlSession.java:134)rn at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)rn at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)rn at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)rn at java.lang.reflect.Method.invoke(Method.java:601)rn at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:358)rn at com.sun.proxy.$Proxy10.insert(Unknown Source)rn at org.mybatis.spring.SqlSessionTemplate.insert(SqlSessionTemplate.java:240)rn at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:79)rn at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:40)rn at com.sun.proxy.$Proxy11.insert(Unknown Source)rn at com.lining.vmservice.service.imp.VMGuestServiceImp.createVMGuest(VMGuestServiceImp.java:44)rn[/code] 论坛

mybatis ResultSet结果集错误

05-30

项目用了springmvc+mybatisrn日志输出为logback,可是每当打印select count(*) from 表 这种sql语句的sql时候,显示的日志有问题,如下:rnlogback.xml中rn[code="xml"]rn rn rn rn rn 这里开启错误也是一样rn[/code]rn打印的日志(部分):rn[code="java"]rn[finance]2014-05-30 13:25:21,979 DEBUG com.company.finance.dao.UserMapper.getCounts [BaseJdbcLogger.java:132] ooo Using Connection [25027515(com.mysql.jdbc.JDBC4Connection@24cfe4)]rn[finance]2014-05-30 13:25:21,980 DEBUG com.company.finance.dao.UserMapper.getCounts [BaseJdbcLogger.java:132] ==> Preparing: select count(*) from pub_user rn[finance]2014-05-30 13:25:21,981 DEBUG com.company.finance.dao.UserMapper.getCounts [BaseJdbcLogger.java:132] ==> Parameters: rn[finance]2014-05-30 13:25:21,983 DEBUG com.company.finance.dao.UserMapper.getCounts [BaseJdbcLogger.java:132] <== Total: 1//下面的一处分页显示都是正常的,3条数据,但是这里打印的信息始终只有1,select count(*) from pub_user结果是3才对rn[finance]2014-05-30 13:25:21,985 DEBUG com.company.finance.dao.UserMapper.findAll [BaseJdbcLogger.java:132] ooo Using Connection [25027515(com.mysql.jdbc.JDBC4Connection@24cfe4)]rn[finance]2014-05-30 13:25:21,986 DEBUG com.company.finance.dao.UserMapper.findAll [BaseJdbcLogger.java:132] ==> Preparing: select * from pub_user limit 5 rn[finance]2014-05-30 13:25:21,987 DEBUG com.company.finance.dao.UserMapper.findAll [BaseJdbcLogger.java:132] ==> Parameters: rn[finance]2014-05-30 13:25:21,989 DEBUG com.company.finance.dao.UserMapper.findAll [BaseJdbcLogger.java:132] <== Total: 3//1.这里都是正确的,显示的3条rn[/code]rndebug查看返回的数量rnint totalCount = baseMapper.getCounts(paramMap);//这里都是3rn这是怎么回事,是logback没有配置正确还是哪里出问题了 问答

mybatis mapper配置错误

05-15

nnnnn n select * from user where id = #idn nnn以上是我的mapper的xml配置文件n然后测试的时候报错 报错信息为:norg.apache.ibatis.exceptions.PersistenceException: n### Error building SqlSession.n### The error may exist in sqlmap/User.xmln### Cause: org.apache.ibatis.builder.BuilderException: Error parsing SQL Mapper Configuration. Cause: org.apache.ibatis.builder.BuilderException: Error creating document instance. Cause: org.xml.sax.SAXParseException; lineNumber: 7; columnNumber: 26; 必须为元素类型 "mapper" 声明属性 "namespace"。n at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:26)n at org.apache.ibatis.session.SqlSessionFactoryBuilder.build(SqlSessionFactoryBuilder.java:82)n at org.apache.ibatis.session.SqlSessionFactoryBuilder.build(SqlSessionFactoryBuilder.java:66)n at com.nullException.mybatis.first.MybatisFirst.init(MybatisFirst.java:22)n at com.nullException.mybatis.first.Test.main(Test.java:8)nCaused by: org.apache.ibatis.builder.BuilderException: Error parsing SQL Mapper Configuration. Cause: org.apache.ibatis.builder.BuilderException: Error creating document instance. Cause: org.xml.sax.SAXParseException; lineNumber: 7; columnNumber: 26; 必须为元素类型 "mapper" 声明属性 "namespace"。n at org.apache.ibatis.builder.xml.XMLConfigBuilder.parseConfiguration(XMLConfigBuilder.java:109)n at org.apache.ibatis.builder.xml.XMLConfigBuilder.parse(XMLConfigBuilder.java:92)n at org.apache.ibatis.session.SqlSessionFactoryBuilder.build(SqlSessionFactoryBuilder.java:80)n ... 3 morenn初学者,问题可能很白痴,有了解的大神帮忙看一下哈 问答

没有更多推荐了,返回首页