mybatis PersistenceException Mapper error - mybatis

I don't know what is wrong.
Something is bad with mapper but everything looks good.
File UserMapper.xml
<?xml version="1.0" encoding="UTF-8"?>
<mapper namespace="com.javacodegeeks.snippets.enterprise.UserMapper">
<select id="addUser" parameterType="int" resultType="com.javacodegeeks.snippets.enterprise.User">
insert into * from users where id = #{id}
</select>
<select id="getUser" parameterType="int" resultType="com.javacodegeeks.snippets.enterprise.User">
select * from com.javacodegeeks.snippets.enterprise.User where id = #{id}
</select>
</mapper>
I get this Error:
Exception in thread "main" org.apache.ibatis.exceptions.PersistenceException:
### Error building SqlSession.
### The error may exist in UserMapper.xml
### 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: 2; columnNumber: 70; Document root element "mapper", must match DOCTYPE root "null".
at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:23)
at org.apache.ibatis.session.SqlSessionFactoryBuilder.build(SqlSessionFactoryBuilder.java:51)
at org.apache.ibatis.session.SqlSessionFactoryBuilder.build(SqlSessionFactoryBuilder.java:35)
at Main.do1(Main.java:105)
at Main.main(Main.java:124)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:134)
Caused 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: 2; columnNumber: 70; Document root element "mapper", must match DOCTYPE root "null".

You can use following doc type. However I find some discrepancy in the code you have copied. Are you sure of INSERT and SELECT statements. I hope its copy mistake
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.javacodegeeks.snippets.enterprise.UserMapper">
<select id="addUser" parameterType="int" resultType="com.javacodegeeks.snippets.enterprise.User">
insert into * from users where id = #{id}
</select>
<select id="getUser" parameterType="int" resultType="com.javacodegeeks.snippets.enterprise.User">
select * from com.javacodegeeks.snippets.enterprise.User where id = #{id}
</select>
</mapper>

Related

How do I use or config Mybatis default LongTypeHandler

sql xml define
When I use Mybatis LongTypeHandler in resultMap, I got error bellow, I don't know why. Does anyone could help on this?
Thanks in advance.
<resultMap id="detail_siteTypeConfig" type="java.util.HashMap">
<result typeHandler="org.apache.ibatis.type.LongTypeHandler" javaType="java.lang.Long" property="siteID" column="siteid"/>
<result typeHandler="org.apache.ibatis.type.LongTypeHandler" javaType="java.lang.Long" property="siteType" column="sitetype"/>
<result typeHandler="com.webex.webapp.common.util.mybatis.StringEmptyTypeHandler" javaType="java.lang.String" property="itemName" column="itemname"/>
<result typeHandler="com.webex.webapp.common.util.mybatis.StringEmptyTypeHandler" javaType="java.lang.String" property="itemValue" column="itemvalue"/>
</resultMap>
<select id="xxxxxx" resultMap="detail_siteTypeConfig">
select siteid, sitetype, itemname, itemvalue from tablexxxx where siteid=#{siteId} and sitetype=#{siteType}
</select>
Error log
Caused by: org.apache.ibatis.builder.BuilderException: Error parsing Mapper XML. The XML location is 'conf/dao/basic/SessionType_Audit.xml'. Cause: org.
apache.ibatis.type.TypeException: Unable to find a usable constructor for class org.apache.ibatis.type.LongTypeHandler
at org.apache.ibatis.builder.xml.XMLMapperBuilder.configurationElement(XMLMapperBuilder.java:123)
at org.apache.ibatis.builder.xml.XMLMapperBuilder.parse(XMLMapperBuilder.java:95)
at org.apache.ibatis.builder.xml.XMLConfigBuilder.mapperElement(XMLConfigBuilder.java:377)
at org.apache.ibatis.builder.xml.XMLConfigBuilder.parseConfiguration(XMLConfigBuilder.java:120)
... 22 more
Caused by: org.apache.ibatis.type.TypeException: Unable to find a usable constructor for class org.apache.ibatis.type.LongTypeHandler
at org.apache.ibatis.type.TypeHandlerRegistry.getInstance(TypeHandlerRegistry.java:457)
at org.apache.ibatis.builder.BaseBuilder.resolveTypeHandler(BaseBuilder.java:143)
at org.apache.ibatis.builder.MapperBuilderAssistant.buildResultMapping(MapperBuilderAssistant.java:427)
at org.apache.ibatis.builder.xml.XMLMapperBuilder.buildResultMappingFromContext(XMLMapperBuilder.java:393)
at org.apache.ibatis.builder.xml.XMLMapperBuilder.resultMapElement(XMLMapperBuilder.java:280)
at org.apache.ibatis.builder.xml.XMLMapperBuilder.resultMapElement(XMLMapperBuilder.java:254)
at org.apache.ibatis.builder.xml.XMLMapperBuilder.resultMapElements(XMLMapperBuilder.java:246)
at org.apache.ibatis.builder.xml.XMLMapperBuilder.configurationElement(XMLMapperBuilder.java:119)
... 25 more
Caused by: java.lang.ClassCastException: org.apache.ibatis.type.LongTypeHandler cannot be cast to org.apache.ibatis.type.TypeHandler
at org.apache.ibatis.type.TypeHandlerRegistry.getInstance(TypeHandlerRegistry.java:455)
... 32 more

MyBatis map-underscore-to-camel-case not working

I am using MyBatis 2.0.0 and have problem: I have a userId and status field that need to retrieve data so I'm using Mybatis for it.
but when I try to get the data the MyBatis don't work and I keep getting the same error.
I've tried to add the lines to application.properties
#mybatis entity scan packages
mybatis.type-aliases-package=com.cnoga.**.dao
#Mapper.xml location
mybatis.mapper-locations=classpath*:/mybatis/**/*.xml
mybatis.configuration.map-underscore-to-camel-case=true
but nothing happend and I still get my error.
I even tried to create the mybatis-config.xml
like this:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN" "http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
<settings>
<setting name="mapUnderscoreToCamelCase" value="true" />
</settings>
</configuration>
and add this line to application.properties instead the lines above:
"mybatis.config-location=classpath:/mybatis-config.xml"
The mapper file:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.proj.user.dao.UserMapper" >
<select id="query4Regist" resultType="java.util.Map" parameterType="java.util.Map" >
select u.user_id userId,
status
from t_user u
left join t_user_group ug on u.user_id = ug.user_id
where u.is_del = 1
and u.status between 0 and 4
and (
u.email = #{account,jdbcType=NVARCHAR}
<if test="countryCode != null and countryCode != ''">
or (u.mobile = #{account,jdbcType=NVARCHAR} and u.country_code = #{countryCode,jdbcType=NVARCHAR})
</if>
)
and (u.region_name = #{regionName} or ug.group_id = 7 or ug.group_id = 8)
order by u.user_id desc offset 0 rows fetch next 1 rows only
</select>
</mapper>
I solved the problem!
The problem was using the map functions.
To use MYBATIS I built struct only for the values ​​I wanted to transfer and I just changed in all the places where I called the map functions to get data from the new struct

org.xml.sax.SAXParseException : Content is not allowed in prolog

This is my project demo, I want to use MyBatis xml configuration. But I got a SAXParseException error, like this
Caused by: org.apache.ibatis.builder.BuilderException: Error creating document instance. Cause: org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 1; Content is not allowed in prolog.
at org.apache.ibatis.parsing.XPathParser.createDocument(XPathParser.java:260)
at org.apache.ibatis.parsing.XPathParser.<init>(XPathParser.java:126)
at org.apache.ibatis.builder.xml.XMLMapperBuilder.<init>(XMLMapperBuilder.java:80)
at org.mybatis.spring.SqlSessionFactoryBean.buildSqlSessionFactory(SqlSessionFactoryBean.java:519)
... 56 more
Caused by: org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 1; Content is not allowed in prolog.
at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:203)
at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.fatalError(ErrorHandlerWrapper.java:177)
at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:400)
at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:327)
at com.sun.org.apache.xerces.internal.impl.XMLScanner.reportFatalError(XMLScanner.java:1472)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$PrologDriver.next(XMLDocumentScannerImpl.java:994)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:602)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:505)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:842)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:771)
at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:141)
at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(DOMParser.java:243)
at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:339)
at org.apache.ibatis.parsing.XPathParser.createDocument(XPathParser.java:258)
... 59 more
this is my mapper xml file:
<?xml version="1.0" encoding="UTF-8" ?>
<mapper namespace="com.ryanqy.mapper.UserMapper" xmlns="http://mybatis.org/schema/mybatis-mapper">
<resultMap id="userResultMap" type="com.ryanqy.entity.UserEntity">
<result column="username" property="username"/>
<result column="password" property="password"/>
</resultMap>
<select id="findUserByUserName" resultMap="userResultMap">
select * from uuc_user where username = #{userName}
</select>
</mapper>
Problem is with your mybatis config:
mybatis:
configuration:
map-underscore-to-camel-case: true
type-aliases-package: com.ryanqy.entity
mapper-locations: mapper
change mapper-locations to:
mapper-locations: mapper/UserMapper.xml
#OR
mapper-locations: mapper/*.xml
If you change, you receive error with missing DOCTYPE in your mapper XML, so add something like this
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">

cvc-complex-type.2.4.b: The content of element 'persistence' is not complete. One of '{"http://xmlns.jcp.org/xml/ns/persistence"...' is expected

I'm trying to deploy a sample JSF 2.3 Application in development, using Eclipse 2018-09 and Payara 5 but it returns me this error:
2018-10-14T15:19:42.783-0300|Severe: Exception during lifecycle processing java.io.IOException: org.xml.sax.SAXParseException; lineNumber: 8; columnNumber: 15; Deployment descriptor file META-INF/persistence.xml in archive [classes]. cvc-complex-type.2.4.b: The content of element 'persistence' is not complete. One of '{"http://xmlns.jcp.org/xml/ns/persistence":persistence-unit}' is expected.
Here is my persistence.xmlfile:
<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://xmlns.jcp.org/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence
http://xmlns.jcp.org/xml/ns/persistence/persistence_2_2.xsd"
version="2.2">
<!-- JPA configuration here. -->
</persistence>
And here is an excerpt of my Console output:
2018-10-14T15:19:38.525-0300|Info: Virtual server server loaded default web module 2018-10-14T15:19:42.779-0300|Severe:enterprise.deployment.backend.invalidDescriptorFailure
2018-10-14T15:19:42.781-0300|Severe: enterprise.deployment.backend.saxParserError
2018-10-14T15:19:42.782-0300|Severe: Exception while deploying the app [project]
2018-10-14T15:19:42.783-0300|Severe: Exception during lifecycle processing
java.io.IOException: org.xml.sax.SAXParseException; lineNumber: 8; columnNumber: 15; Deployment descriptor file META-INF/persistence.xml in archive [classes]. cvc-complex-type.2.4.b: The content of element 'persistence' is not complete. One of '{"http://xmlns.jcp.org/xml/ns/persistence":persistence-unit}' is expected.
at org.glassfish.javaee.core.deployment.DolProvider.processDOL(DolProvider.java:207)
at org.glassfish.javaee.core.deployment.DolProvider.load(DolProvider.java:223)
at org.glassfish.javaee.core.deployment.DolProvider.load(DolProvider.java:91)
at com.sun.enterprise.v3.server.ApplicationLifecycle.loadDeployer(ApplicationLifecycle.java:933)
at com.sun.enterprise.v3.server.ApplicationLifecycle.setupContainerInfos(ApplicationLifecycle.java:873)
at com.sun.enterprise.v3.server.ApplicationLifecycle.prepare(ApplicationLifecycle.java:383)
at org.glassfish.deployment.admin.DeployCommand.execute(DeployCommand.java:540)
at com.sun.enterprise.v3.admin.CommandRunnerImpl$2$1.run(CommandRunnerImpl.java:549)
at com.sun.enterprise.v3.admin.CommandRunnerImpl$2$1.run(CommandRunnerImpl.java:545)
at java.security.AccessController.doPrivileged(Native Method)
at javax.security.auth.Subject.doAs(Subject.java:360)
at com.sun.enterprise.v3.admin.CommandRunnerImpl$2.execute(CommandRunnerImpl.java:544)
at com.sun.enterprise.v3.admin.CommandRunnerImpl$3.run(CommandRunnerImpl.java:575)
at com.sun.enterprise.v3.admin.CommandRunnerImpl$3.run(CommandRunnerImpl.java:567)
at java.security.AccessController.doPrivileged(Native Method)
at javax.security.auth.Subject.doAs(Subject.java:360)
at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:566)
at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:1475)
at com.sun.enterprise.v3.admin.CommandRunnerImpl.access$1300(CommandRunnerImpl.java:111)
at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1857)
at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1733)
at com.sun.enterprise.v3.admin.AdminAdapter.doCommand(AdminAdapter.java:564)
at com.sun.enterprise.v3.admin.AdminAdapter.onMissingResource(AdminAdapter.java:251)
at org.glassfish.grizzly.http.server.StaticHttpHandlerBase.service(StaticHttpHandlerBase.java:166)
at com.sun.enterprise.v3.services.impl.ContainerMapper$HttpHandlerCallable.call(ContainerMapper.java:516)
at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:213)
at org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:182)
at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:156)
at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:218)
at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:95)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:260)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:177)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:109)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:88)
at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:53)
at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:524)
at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:89)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:94)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:33)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:114)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:569)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:549)
at java.lang.Thread.run(Thread.java:748)
Caused by: org.xml.sax.SAXParseException; lineNumber: 8; columnNumber: 15; Deployment descriptor file META-INF/persistence.xml in archive [classes]. cvc-complex-type.2.4.b: The content of element 'persistence' is not complete. One of '{"http://xmlns.jcp.org/xml/ns/persistence":persistence-unit}' is expected.
at com.sun.enterprise.deployment.io.DeploymentDescriptorFile.read(DeploymentDescriptorFile.java:331)
at com.sun.enterprise.deployment.archivist.ExtensionsArchivist.open(ExtensionsArchivist.java:179)
at com.sun.enterprise.deployment.archivist.PersistenceArchivist.readPersistenceDeploymentDescriptor(PersistenceArchivist.java:158)
at com.sun.enterprise.deployment.archivist.WarPersistenceArchivist.open(WarPersistenceArchivist.java:99)
at com.sun.enterprise.deployment.archivist.Archivist.readRestDeploymentDescriptors(Archivist.java:403)
at com.sun.enterprise.deployment.archivist.Archivist.readDeploymentDescriptors(Archivist.java:394)
at com.sun.enterprise.deployment.archivist.Archivist.open(Archivist.java:269)
at com.sun.enterprise.deployment.archivist.Archivist.open(Archivist.java:278)
at com.sun.enterprise.deployment.archivist.Archivist.open(Archivist.java:239)
at com.sun.enterprise.deployment.archivist.ApplicationFactory.openArchive(ApplicationFactory.java:161)
at org.glassfish.javaee.core.deployment.DolProvider.processDOL(DolProvider.java:199)
... 42 more
Caused by: org.xml.sax.SAXParseException; lineNumber: 8; columnNumber: 15; cvc-complex-type.2.4.b: The content of element 'persistence' is not complete. One of '{"http://xmlns.jcp.org/xml/ns/persistence":persistence-unit}' is expected.
at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:203)
at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.error(ErrorHandlerWrapper.java:134)
at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:396)
at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:327)
at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:284)
at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator$XSIErrorReporter.reportError(XMLSchemaValidator.java:453)
at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.reportSchemaError(XMLSchemaValidator.java:3231)
at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.elementLocallyValidComplexType(XMLSchemaValidator.java:3207)
at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.elementLocallyValidType(XMLSchemaValidator.java:3154)
at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.processElementContent(XMLSchemaValidator.java:3056)
at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.handleEndElement(XMLSchemaValidator.java:2135)
at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.endElement(XMLSchemaValidator.java:854)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanEndElement(XMLDocumentFragmentScannerImpl.java:1782)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:2967)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:602)
at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(XMLNSDocumentScannerImpl.java:112)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:505)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:842)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:771)
at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:141)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1213)
at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:643)
at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl.parse(SAXParserImpl.java:327)
at com.sun.enterprise.deployment.io.DeploymentDescriptorFile.read(DeploymentDescriptorFile.java:321)
... 52 more
How can I fix this?
Thanks.
You need to provide persistence-unit information to persistence.xml file
Here is an example: https://www.thoughts-on-java.org/jpa-persistence-xml/
Hope it help!

MyBatis issue: Unrecognized jdbcType

While trying to convert my app from using MyBatis [it was iBatis before], I've been getting the following error, in spite of trying to make so many different kinds of changes to the code: What am I doing wrong? Any help would be really really really great!!!
Error message:
`Caused by: org.springframework.jdbc.UncategorizedSQLException: ### Error querying database. Cause: com.ibm.db2.jcc.am.SqlException: [jcc][10271][10296][3.58.82] Unrecognized JDBC type: -10. ERRORCODE=-4228, SQLSTATE=null
`
`### The error may exist in Path-to-XML-File.XML`
`### The error may involve namespace.resultMap-name`
`### The error occurred while executing a query`
`### SQL: {call name-of-stored-proc(?)}`
`### Cause: com.ibm.db2.jcc.am.SqlException: [jcc][10271][10296][3.58.82] Unrecognized JDBC type: -10. ERRORCODE=-4228, SQLSTATE=null`
`; uncategorized SQLException for SQL []; SQL state [null]; error code [-4228]; [jcc][10271][10296][3.58.82] Unrecognized JDBC type: -10. ERRORCODE=-4228, SQLSTATE=null; nested exception is com.ibm.db2.jcc.am.SqlException: [jcc][10271][10296][3.58.82] Unrecognized JDBC type: -10. ERRORCODE=-4228, SQLSTATE=null`
XML File: `
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="Namespace-name">
<resultMap id="retrieveReports-results" type="Folder-structure-to-Java-file" autoMapping="true">
<result property="name" column="REPORT_NAME"/>
<result property="location" column="REPORT_DIRECTORY"/>
<result property="key" column="REPORT_KEY"/>
<result property="executable" column="EXECUTABLE"/>
<result property="commandLine" column="COMMAND_LINE"/>
<result property="commandLineFormat" column="COMMAND_LINE_FORMAT"/>
</resultMap>
<select id="retrieveReports" resultType="java.util.Map" statementType="CALLABLE">
{call prc_sel_reports(#{reports,jdbcType=CURSOR,javaType=java.sql.ResultSet,mode=OUT,resultMap=retrieveReports-results})}
</select>
</mapper>`
Java code:
try {
List < Report > reports = super.getSqlSession().selectList("retrieveReports");
if(log.isDebugEnabled()){
log.debug("Retrieved " + reports.size() + " reports, in method: retrieveReports()");
}
return reports;
// Attempt to catch different kinds of exceptions.
} catch (Exception e) {
throw new RuntimeException("Exception caught while trying to retrieve reports", e);
}
You have to specify a parameterType in the select statement, either map or custom class. An instance has to be passed on statement invocation.
resultType is not used, then irrelevant.
Procedure actually writes in a field of the "input" parameter passed to mybatis statement, and the statement does not return anything.
Mapper interface would be: void retrieveReports(Map<String, Object> params);
And your call:
Map<String, Object> params = new HashMap<String, Object>();
session.selectList("retrieveReports", params);
List<Report> reports = (List<Report>)params.get("reports");
Param may also be a custom type with property private List<Report> reports;.