0

I have been trying to connect to a mysql database using the Mybatis framework by following several tutorials. The main one being http://webappdevelopmentlab.com/mybatis-tutorial-quick-start-guide/

I've been trying to fix this problem for two days and can't figure out if its a problem with my config or the syntax in my mapper xml. The database i created in mysql has the same names for the columns as the attributes in the java class.

The error says it could be in the mapper xml, but I don't see anything wrong with it.

This is using just a standard java project, and not maven.

Here are my files within the Project File Structure

mybatis-config.xml

<?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>

    <environments default="development">
      <environment id="development">
        <transactionManager type="JDBC"/>

            <dataSource type="UNPOOLED">
                <property name="driver" value="com.mysql.jdbc.Driver"/>
                <property name="url" value="jdbc:mysql://localhost:3306/pmsdb"/>
                <property name="username" value="root"/>
                <property name="password" value="!Theold5075"/>
            </dataSource>
        </environment>
    </environments>

    <mappers>
        <mapper resource="resource/DeliverableMapper.xml"/>
    </mappers>

</configuration>

DeliverableMapper.xml

<?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">

<mapper namespace="resource.DeliverableMapper.xml">


    <resultMap id="deliverableMap" type="domains.Deliverable">

        <id property="ID" column="ID" javaType="int" jdbcType="NUMERIC"/>
        <result property="name"  column="name" javaType="String" jdbcType="VARCHAR"/>
        <result property="description"  column="description" javaType="String" jdbcType="VARCHAR"/>
        <result property="dueDate"  column="dueDate" javaType="java.util.Date" jdbcType="DATE"/>

    </resultMap>


    <select id="selectAllDeliverables" resultMap="deliverableMap">
        select * from deliverables
    <select/>


</mapper>

Deliverable.java

public class Deliverable {

private int ID;
private String name;
private String description;
private Date dueDate;

//private TreeSet<Requirement> listOfRequirements;
//private TreeSet<Task> listOfTasks;

@SuppressWarnings("deprecation")
public Deliverable(){
    ID = 0;
    name = "PLACEHOLDER";
    description = "PLACEHOLDER";
    dueDate = new Date(2019,8,5);
}

public int getID() {
    return ID;
}
public void setID(int iD) {
    ID = iD;
}
public String getName() {
    return name;
}
public void setName(String name) {
    this.name = name;
}
public String getDescription() {
    return description;
}
public void setDescription(String description) {
    this.description = description;
}
@SuppressWarnings("deprecation")
public String getDueDate() {
    return dueDate.getYear() + "-" + dueDate.getMonth() + "-" + dueDate.getDate();
}

@SuppressWarnings("deprecation")
public void setDueDate(int year, int month, int day){
    dueDate.setYear(year);
    dueDate.setDate(day);
    dueDate.setMonth(month);
    }
}

This is the error i get

Exception in thread "main"   org.apache.ibatis.exceptions.PersistenceException: 
### Error building SqlSession.
### The error may exist in resource/DeliverableMapper.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: 5; columnNumber: 52; Document root element "mapper", must match DOCTYPE root "configuration".
at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:30)
at org.apache.ibatis.session.SqlSessionFactoryBuilder.build(SqlSessionFactoryBuilder.java:80)
at org.apache.ibatis.session.SqlSessionFactoryBuilder.build(SqlSessionFactoryBuilder.java:64)
at drivers.DBController.main(DBController.java:23)
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: 5; columnNumber: 52; Document root element "mapper", must match DOCTYPE root "configuration".
at org.apache.ibatis.builder.xml.XMLConfigBuilder.parseConfiguration(XMLConfigBuilder.java:121)
at org.apache.ibatis.builder.xml.XMLConfigBuilder.parse(XMLConfigBuilder.java:99)
at org.apache.ibatis.session.SqlSessionFactoryBuilder.build(SqlSessionFactoryBuilder.java:78)
... 2 more
Caused by: org.apache.ibatis.builder.BuilderException: Error creating document instance.  Cause: org.xml.sax.SAXParseException; lineNumber: 5; columnNumber: 52; Document root element "mapper", must match DOCTYPE root "configuration".
at org.apache.ibatis.parsing.XPathParser.createDocument(XPathParser.java:259)
at org.apache.ibatis.parsing.XPathParser.<init>(XPathParser.java:125)
at org.apache.ibatis.builder.xml.XMLMapperBuilder.<init>(XMLMapperBuilder.java:78)
at org.apache.ibatis.builder.xml.XMLConfigBuilder.mapperElement(XMLConfigBuilder.java:372)
at org.apache.ibatis.builder.xml.XMLConfigBuilder.parseConfiguration(XMLConfigBuilder.java:119)
... 4 more
Caused by: org.xml.sax.SAXParseException; lineNumber: 5; columnNumber: 52; Document root element "mapper", must match DOCTYPE root "configuration".
at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(Unknown Source)
at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.error(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDValidator.rootElementSpecified(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDValidator.handleStartElement(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDValidator.startElement(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanStartElement(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$ContentDriver.scanRootElementHook(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$PrologDriver.next(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(Unknown Source)
at org.apache.ibatis.parsing.XPathParser.createDocument(XPathParser.java:257)
... 8 more

1 Answer 1

1

The attribute namespace in the tag mapper should be the interface of the mapper, here it should be data.DeliverableMapper.
Like this:

<mapper namespace="data.DeliverableMapper">
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you for the fast reply! I literally just noticed the error right before i saw the reply.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.