Very strange "Error building SqlSession"

273 views
Skip to first unread message

Nir Oz

unread,
Sep 4, 2011, 11:26:32 AM9/4/11
to mybatis-user
Hi Group,

Been working with Ibatis for some time now and had no issues until
yesterday.
I have restarted the server after making really basic logging change
(added a System.out... in one of the methods), after the restart I got
the below error which I am unable to find a solution for. any other
method I am calling gives me the same error.

Nothing changed in the configuration files or code except for the
SYstem.out statement and I can't find any existence of
"encodingguration" in my project. the same methods used to work until
yesterday restart. I rolled back the System.out change and i am still
getting the same error. The same code works for me fine locally but
once i am deploying it to the server it just unable to start a
session.

Locally i am using windows machine, the server is linux/tomcat/mySql

Any idea/suggestion why such thing should happen and how to resolve?
Thanks

### Error building SqlSession.
### The error may exist in SQL Mapper Configuration
### Cause: org.apache.ibatis.builder.BuilderException: Error creating
document instance. Cause: org.xml.sax.SAXParseException: The ' = '
character must follow "encodingguration" in the XML declaration.
at
org.apache.xmlrpc.server.ReflectiveXmlRpcHandler.invoke(ReflectiveXmlRpcHandler.java:
129)
at
org.apache.xmlrpc.server.ReflectiveXmlRpcHandler.execute(ReflectiveXmlRpcHandler.java:
106)
at
org.apache.xmlrpc.server.XmlRpcServerWorker.execute(XmlRpcServerWorker.java:
46)
at
org.apache.xmlrpc.server.XmlRpcServer.execute(XmlRpcServer.java:86)
at
org.apache.xmlrpc.server.XmlRpcStreamServer.execute(XmlRpcStreamServer.java:
200)
at
org.apache.xmlrpc.webserver.XmlRpcServletServer.execute(XmlRpcServletServer.java:
112)
at
com.alon.springframework.mvc.controller.XmlRpcController.handleRequestInternal(XmlRpcController.java:
28)
at
org.springframework.web.servlet.mvc.AbstractController.handleRequest(AbstractController.java:
153)
at
org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter.handle(SimpleControllerHandlerAdapter.java:
48)
at
org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:
771)
at
org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:
716)
at
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:
647)
at
org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:
563)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:
637)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:
717)
at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:
290)
at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:
206)
at
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:
233)
at
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:
191)
at
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:
127)
at
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:
102)
at
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:
109)
at
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:
298)
at
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:
852)
at org.apache.coyote.http11.Http11Protocol
$Http11ConnectionHandler.process(Http11Protocol.java:588)
at org.apache.tomcat.util.net.JIoEndpoint
$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Thread.java:619)
Caused by: org.apache.ibatis.exceptions.IbatisException:

sanjeev kumar

unread,
Sep 4, 2011, 1:40:36 PM9/4/11
to mybati...@googlegroups.com
Can you try deleting the cache, or temp files.
Also check the classfiles in classpath is using.
I did the above when I get the problem where in after restart, and
rollback problem was not resolved.

Not sure, if that can help, but can you please try these?

Nir Oz

unread,
Sep 5, 2011, 2:36:37 AM9/5/11
to mybatis-user
Hi Sanjeev,

Thanks for the help.
I have deleted the cache yesterday but it didn't help, what should I
look for in the classpath (i am sure nothing was changed in the
classpath)?
Another strange discovery/observation is that when I start tomcat in
debug (jpda) mode it is all working fine but when I start it in
regular mode it is not working.

Thoughts?

Regards,

sanjeev kumar

unread,
Sep 5, 2011, 12:02:55 PM9/5/11
to mybati...@googlegroups.com
It is strange
Can you try to delete the deployment n redeploy and restart the tomcat
after deleting web app folder from work dir.

not sure will help, but we can try that out that as well.

Nir Oz

unread,
Sep 5, 2011, 1:53:46 PM9/5/11
to mybatis-user
Hi Sanjeev,

Thanks again for trying to help, it seems like the plot is getting
thicker :)

I did some more testing and debugging trying to figure out the issue
and found out that only one use case flush the issue and this is just
weird.
The API I developed are being called by mobile devices (iPhone and
Android), when I use Android or my local test client for the first
call (the call which initiate the iBatis sqlSession) then everything
works fine and there is no issue for any other client to connect.
However, when I use iPhone for the first call (same call which
initiate the iBatis sqlSession) then the error is showing and no other
client can use the service/API.

This is really wired and I got no idea why iPhone call should cause
the issue and other clients shouldn't.
Any suggestions?

Thanks

nir

sanjeev kumar

unread,
Sep 5, 2011, 1:59:52 PM9/5/11
to mybati...@googlegroups.com
Thanks you, to let me know that.

Would you mind if you can try, to install the tomcat on MAC OS and try
with the api call?

You are running the tomcat on windowOS? from where api is called right?

Nir Oz

unread,
Sep 5, 2011, 2:12:01 PM9/5/11
to mybatis-user
When I run the tomcat locally (Windows machine) I don't see the issue,
however, I can't test the iphone against my local machine (at least
until tomorrow when the iPhone developer will be online and can
compile a version which will point to my local machine).

When I run the tomcat on linux machine (QA) then i can see the issue
as described in previous posts.

to install tomcat on Mac would be an achievable task but not sure why
it should make a difference (also might take some time until I can
arrange it)?

sanjeev kumar

unread,
Sep 5, 2011, 2:31:09 PM9/5/11
to mybati...@googlegroups.com
I know it should not make difference, but seems me could be the
problem with the OS system, though I am not 100 % sure. Would like to
consider that if OS doing anything thing or not. As I believe API
written in java, and java is independent of OS, and we seen things are
very strange, which I think OS can be causing that, for which I am not
very much sure of, but thought if it can be try on the same OS where
in iPhone is running. What do you think?

Just curious to know, how you are calling an API? you are making the
n/w which call the API's functions right?

François Schiettecatte

unread,
Sep 5, 2011, 2:46:00 PM9/5/11
to mybati...@googlegroups.com
I would be very curious to take a look at your mybatis config file and one of your mapper files, they maybe some weird characters in there, would you mind posting them?

François

Nir Oz

unread,
Sep 5, 2011, 5:07:30 PM9/5/11
to mybatis-user
Guys,

Appreciate the help.

I did more testing trying to confirm the root cause of the issue. I
was able to replicate it locally by pointing the iPhone application to
my local machine (Windows based). I am getting similar issue but with
different error (see bottom for full exception log) "Caused by:
org.apache.ibatis.builder.BuilderException: Error creating document
instance. Cause: org.xml.sax.SAXParseException: The document type
declaration for root element type "configurations.apache.org" must end
with '>'."

See below my config file, where ever you see "?" instead of a proper
string it means i replaced it to protect my client identity.

*****************Config start **********************
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration PUBLIC "-//ibatis.apache.org//DTD Config 3.0//
EN" "http://ibatis.apache.org/dtd/ibatis-3-config.dtd">
<configuration>
<typeAliases>
<typeAlias alias="User" type="com.?.model.User"/>
<typeAlias alias="Address" type="com.?.model.Address"/>
<typeAlias alias="OpeningHours" type="com.?.model.OpeningHours"/>
<typeAlias alias="Application" type="com.?.model.Application"/>
<typeAlias alias="Session" type="com.?.model.Session"/>
<typeAlias alias="UserBusiness" type="com.?.model.UserBusiness"/>
<typeAlias alias="Country" type="com.?.model.Country"/>
<typeAlias alias="Business" type="com.?.model.Business"/>
<typeAlias alias="BusinessProfile"
type="com.?.model.BusinessProfile"/>
<typeAlias alias="Branch" type="com.?.model.Branch"/>
<typeAlias alias="ServiceCategory"
type="com.?.model.ServiceCategory"/>
<typeAlias alias="Product" type="com.?.model.Product"/>
<typeAlias alias="ProductCategory"
type="com.?.model.ProductCategory"/>
<typeAlias alias="ProductMessage" type="com.?.model.ProductMessage"/
>
<typeAlias alias="UserMessage" type="com.?.model.UserMessage"/>
<typeAlias alias="UserProfile" type="com.?.model.UserProfile"/>
<typeAlias alias="Card" type="com.?.model.Card"/>
<typeAlias alias="Message" type="com.?.model.Message"/>
<typeAlias alias="Exchange" type="com.?.model.Exchange"/>
<typeAlias alias="FeaturedBusiness"
type="com.?.model.FeaturedBusiness"/>
</typeAliases>
<mappers>
<mapper resource="com/?/data/UserMapper.xml"/>
<mapper resource="com/?/data/ApplicationMapper.xml"/>
<mapper resource="com/?/data/SessionMapper.xml"/>
<mapper resource="com/?/data/LocationMapper.xml"/>
<mapper resource="com/?/data/BusinessMapper.xml"/>
<mapper resource="com/?/data/CategoryMapper.xml"/>
<mapper resource="com/?/data/AddressMapper.xml"/>
<mapper resource="com/?/data/MessageMapper.xml"/>
<mapper resource="com/?/data/ProductMapper.xml"/>
</mappers>
</configuration>
*****************Config end **********************

here is a sample mapper (took the simplest i could find)

*****************Mapper Start ***********************

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//ibatis.apache.org//DTD Mapper 3.0//EN"
"http://ibatis.apache.org/dtd/ibatis-3-mapper.dtd">
<mapper namespace="com.?.data.mapper.SessionMapper">
<sql id="sessionColumns"> id,application_id as
applicationId,expiry,session_key as sessionKey </sql>
<select id="isValidSessionKey" parameterType="java.util.Map"
resultType="boolean">
SELECT COUNT(*) FROM Session where session_key=#{session_key} and
user_id=#{user_id}
</select>
<select id="selectActiveSession" parameterType="java.lang.String"
resultType="Session">
SELECT COUNT(*) FROM Session where session_key=#{sessionKey} and
expiry>current_timestamp
</select>

<insert id="insertSession" parameterType="Session" flushCache="true"
statementType="PREPARED" useGeneratedKeys="true" keyProperty="id"
timeout="20000">
insert into Session (
<if test="applicationId != null">
application_id,
</if>
<if test="deviceId != null">
device_id,
</if>
creation_date,
last_modified_date,
<if test="createdByCompanyId != null">
created_by_company_id,
</if>
<if test="createdByUserId != null">
created_by_user_id,
</if>
<if test="lastModifiedByUserId != null">
last_modified_by_user_id,
</if>
is_active,
<if test="expiry != null">
expiry,
</if>
<if test="sessionKey != null">
session_key,
</if>
<if test="userId != null">
user_id
</if>
)
values (
<if test="applicationId != null">
#{applicationId},
</if>
<if test="deviceId != null">
#{deviceId},
</if>
CURRENT_TIMESTAMP,
CURRENT_TIMESTAMP,
<if test="createdByCompanyId != null">
#{createdByCompanyId},
</if>
<if test="createdByUserId != null">
#{createdByUserId},
</if>
<if test="lastModifiedByUserId != null">
#{lastModifiedByUserId},
</if>
#{isActive},
<if test="expiry != null">
#{expiry},
</if>
<if test="sessionKey != null">
#{sessionKey},
</if>
<if test="userId != null">
#{userId}
</if>
)
</insert>

</mapper>

*****************Mapper End ************************



*****************Exception start **********************

### Error building SqlSession.
### The error may exist in SQL Mapper Configuration
### Cause: org.apache.ibatis.builder.BuilderException: Error creating
document instance. Cause: org.xml.sax.SAXParseException: The document
type declaration for root element type "configurations.apache.org"
must end with '>'.
at
org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:
8)
at
org.apache.ibatis.session.SqlSessionFactoryBuilder.build(SqlSessionFactoryBuilder.java:
32)
at
org.apache.ibatis.session.SqlSessionFactoryBuilder.build(SqlSessionFactoryBuilder.java:
15)
at
com.alon.ibatis.config.IbatisAppConfigImpl.sqlSessionFactoryBuilder(IbatisAppConfigImpl.java:
48)
at
com.alon.ibatis.config.IbatisAppConfigImpl.sqlSession(IbatisAppConfigImpl.java:
59)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:
39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:
25)
at java.lang.reflect.Method.invoke(Method.java:597)
at
org.apache.xmlrpc.server.ReflectiveXmlRpcHandler.invoke(ReflectiveXmlRpcHandler.java:
115)
... 38 more
Caused by: org.apache.ibatis.builder.BuilderException: Error creating
document instance. Cause: org.xml.sax.SAXParseException: The document
type declaration for root element type "configurations.apache.org"
must end with '>'.
at
org.apache.ibatis.parsing.XPathParser.createDocument(XPathParser.java:
136)
at
org.apache.ibatis.parsing.XPathParser.<init>(XPathParser.java:32)
at
org.apache.ibatis.builder.xml.XMLConfigBuilder.<init>(XMLConfigBuilder.java:
47)
at
org.apache.ibatis.session.SqlSessionFactoryBuilder.build(SqlSessionFactoryBuilder.java:
28)
... 48 more
Caused by: org.xml.sax.SAXParseException: The document type
declaration for root element type "configurations.apache.org" must end
with '>'.
at
org.apache.xerces.util.ErrorHandlerWrapper.createSAXParseException(Unknown
Source)
at
org.apache.xerces.util.ErrorHandlerWrapper.fatalError(Unknown Source)
at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown
Source)
at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown
Source)
at org.apache.xerces.impl.XMLScanner.reportFatalError(Unknown
Source)
at
org.apache.xerces.impl.XMLDocumentScannerImpl.scanDoctypeDecl(Unknown
Source)
at org.apache.xerces.impl.XMLDocumentScannerImpl
$PrologDispatcher.dispatch(Unknown Source)
at
org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown
Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown
Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown
Source)
at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
at org.apache.xerces.parsers.DOMParser.parse(Unknown Source)
at org.apache.xerces.jaxp.DocumentBuilderImpl.parse(Unknown
Source)
at
org.apache.ibatis.parsing.XPathParser.createDocument(XPathParser.java:
134)
... 51 more
Caused by:
org.apache.ibatis.exceptions.IbatisException:

*****************Exception end *************************


On Sep 5, 7:46 pm, François Schiettecatte <fschietteca...@gmail.com>
wrote:
> I would be very curious to take a look at your mybatis config file and one of your mapper files, they maybe some weird characters in there, would you mind posting them?
>
> François
>
> On Sep 5, 2011, at 2:31 PM, sanjeev kumar wrote:
>
>
>
>
>
>
>
> > I know it should not make difference, but seems me could be the
> > problem with the OS system, though I am not 100 % sure. Would like to
> > consider that if OS doing anything thing or not. As I believe  API
> > written in java, and java is independent of OS, and we seen things are
> > very strange, which I think OS can be causing that, for which I am not
> > very much sure of, but thought if it can be try on the same OS where
> > in iPhone is running. What do you think?
>
> > Just curious to know,  how you are calling an API?  you are making the
> > n/w which call the API's functions   right?
>

raupach

unread,
Sep 5, 2011, 5:21:27 PM9/5/11
to mybatis-user
Did you try

<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">

instead of

<!DOCTYPE mapper PUBLIC "-//ibatis.apache.org//DTD Mapper 3.0//EN"
"http://ibatis.apache.org/dtd/ibatis-3-mapper.dtd">


> ...
>
> read more »

Nir Oz

unread,
Sep 5, 2011, 5:41:58 PM9/5/11
to mybatis-user
I've changed all the mappers to
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://
mybatis.org/dtd/mybatis-3-mapper.dtd">

and the config file to
<!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-config.dtd">

And now i get the following error
Caused by: org.xml.sax.SAXParseException: The document type
declaration for root element type "configuration" must end with '>'.

What drives me insane is that it all works fine except when I initiate
the sqlSession using a request that comes from iPhone (and the silly
fact that this issue presented itself out of the blue 2 days ago
without me changing any of the code).

Thoughts?
> org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactor y.java:
> 8)
>         at
> org.apache.ibatis.session.SqlSessionFactoryBuilder.build(SqlSessionFactoryB uilder.java:
> 32)
>         at
> org.apache.ibatis.session.SqlSessionFactoryBuilder.build(SqlSessionFactoryB uilder.java:
> 15)
>         at
> com.alon.ibatis.config.IbatisAppConfigImpl.sqlSessionFactoryBuilder(IbatisA ppConfigImpl.java:
> 48)
>         at
> com.alon.ibatis.config.IbatisAppConfigImpl.sqlSession(IbatisAppConfigImpl.j ava:
> ...
>
> read more »

Nir Oz

unread,
Sep 5, 2011, 5:43:16 PM9/5/11
to mybatis-user
the API calls are over XML-RPC which is fairly outdated these days but
still works fine.
Reply all
Reply to author
Forward
0 new messages