|
Hello,every one: I defined two complex result map.My application failed when creating database connection via MyBatis. Here is my exception message: ### Error building SqlSession.
### The error may exist in business/mybatis/xml/mysql/user.map.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: The content of element type "association" must match "(constructor?,id*,result*,association*,collection*,discriminator?)".
org.apache.ibatis.exceptions.PersistenceException: ### Error building SqlSession. ### The error may exist in business/mybatis/xml/mysql/user.map.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: The content of element type "association" must match "(constructor?,id*,result*,association*,collection*,discriminator?)".
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 business.mybatis.helper.SqlSessionHelper.createFactory(SqlSessionHelper.java:57)
at business.mybatis.helper.SqlSessionHelper.<init>(SqlSessionHelper.java:24)
at business.mybatis.helper.SqlSessionHelper.<clinit>(SqlSessionHelper.java:18)
at business.exemption.RequestHandler.process(RequestHandler.java:58)
.... My sqlMapConfig.xml file: <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE configuration PUBLIC "-//ibatis.apache.org//DTD Config 3.0//EN"
<configuration> <typeAliases> <typeAlias alias="ExemptionType" type="com.exactor.ns_ee.ExemptionType"/>
<typeAlias alias="FederalIdType" type="com.exactor.ns_ee.FederalIdType"/> <typeAlias alias="ExemptCustomerType" type="com.exactor.ns_ee.ExemptCustomerType"/>
<typeAlias alias="ExemptionStatusType" type="com.exactor.ns_ee.ExemptionStatusType"/> <typeAlias alias="User" type="business.exemption.User"/>
<typeAlias alias="ExemptionRecord" type="business.exemption.ExemptionRecord2"/> <typeAlias alias="ExemptRegionType" type="com.exactor.ns_ee.ExemptRegionType"/>
<typeAlias alias="QueryCondition" type="business.exemption.QueryCondition"/> <typeAlias alias="FederalIdClassificationType" type="com.exactor.ns_ee.FederalIdClassificationType"/>
<typeAlias alias="DateConverter" type="business.mybatis.helper.DateConverter"/> <typeAlias alias="FederalIdTypeConverter" type="business.mybatis.helper.FederalIdTypeConverter"/>
<typeAlias alias="ExemptionStatusTypeConverter" type="business.mybatis.helper.ExemptionStatusTypeConverter"/> </typeAliases>
<typeHandlers> <typeHandler javaType="java.util.Date" jdbcType="INTEGER" handler="DateConverter"/>
<typeHandler javaType="FederalIdClassificationType" jdbcType="VARCHAR" handler="FederalIdTypeConverter"/> <typeHandler javaType="ExemptionStatusType" jdbcType="INTEGER" handler="ExemptionStatusTypeConverter"/>
</typeHandlers> <environments default="exactorprod">
<environment id="exactorprod"> <transactionManager type="JDBC"/>
<dataSource type="POOLED"> <property name="driver" value="com.mysql.jdbc.Driver"/>
<property name="url" value="jdbc:mysql://10.23.1.118:3306/exactordev?zeroDateTimeBehavior=convertToNull&characterEncoding=utf8&useConfigs=maxPerformance&useDynamicCharsetInfo=false&useUnicode=true" />
<property name="username" value="exactordev"/>
<property name="password" value="exactordev"/>
<property name="poolPingQuery" value="select 1"/>
<property name="poolPingEnabled" value="true"/>
<property name="poolPingConnectionsNotUsedFor" value="14400"/>
</dataSource> </environment> </environments>
<mappers> <mapper resource="business/mybatis/xml/mysql/user.map.xml" />
</mappers> </configuration> My user.map.xml file:
<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE mapper
PUBLIC "-//ibatis.apache.org//DTD Mapper 3.0//EN"
<mapper namespace="mybatis.xml.UserMapper"> <resultMap id="userMap" type="User">
<id property="accountId" column="account_id" /> <result property="accountStatus" column="account_status"/>
<result property="userId" column="user_id" /> <result property="signatureEnable" column="digital_signature_enabled"/>
<result property="key" column="digital_signature"/> </resultMap>
<select id="getUser" parameterType="User" resultMap="userMap" >
select account.id as account_id,account.account_status,users.id as user_id,users.DIGITAL_SIGNATURE,users.DIGITAL_SIGNATURE_ENABLED
from account inner join users on account.id=users.account_id where account.uuid = #{merchantId,jdbcType=VARCHAR} and users.login like binary #{userName,jdbcType=VARCHAR}
</select> <resultMap id="exemptionRecordMap" type="ExemptionRecord">
<result property="accountId" column="account_id"/> <association property="exemption" column="exemption_id" javaType="ExemptionType" resultMap="exemptionMap"/>
</resultMap> <resultMap id="exemptionMap" type="ExemptionType">
<id property="exemptionId" column="exemption_id" /> <association property="ExemptionCustomer" javaType="ExemptCustomerType">
<id property="customerId" column="customer_id" /> <result property="customerName" column="customer_name" />
<result property="street1" column="address1" /> <result property="street2" column="address2" />
<result property="city" column="city" /> <result property="stateOrProvince" column="state" />
<result property="postalCode" column="zipcode" /> <association property="federalId" javaType="FederalIdType">
<id property="federalId" column="federal_id" javaType="FederalIdClassificationType" jdbcType="VARCHAR"/>
<result property="federalIdType" column="federal_id_type"/>
</association> <result property="phoneNumber" column="phone_number" />
<result property="email" column="email" /> <result property="active" column="active" javaType="ExemptionStatusType" jdbcType="INTEGER"/>
<result property="country" column="country" /> </association>
<collection property="exemptionRegions" ofType="ExemptRegionType"> <result property="country" column="country_code" />
<result property="stateOrProvince" column="state_code" /> <result property="reason" column="reason_code" />
<result property="taxOrPermitId" column="permit_id" /> <result property="startDate" column="start_date" javaType="java.util.Date" jdbcType="INTEGER"/>
<result property="endDate" column="end_date" javaType="java.util.Date" jdbcType="INTEGER"/> </collection>
</resultMap> <select id="getExemption" parameterType="QueryCondition" resultMap="exemptionRecordMap" >
select exemption.account_id,exemption.id as exemption_id,exemption.customer_id,exemption.customer_name,exemption.address1,exemption.address2,exemption.city,
exemption.state,exemption.zipcode,exemption.federal_id_type,exemption.federal_id,exemption.phone_number,exemption.email,exemption.active, exemption.country_code as country,exemption_regions.country_code,exemption_regions.state_code,exemption_regions.reason_code,exemption_regions.permit_id,
date_format(cast(exemption_regions.start_date as char(8)),'%Y%m%d') as start_date, date_format(cast(exemption_regions.end_date as char(8)),'%Y%m%d') as end_date
from exemption left join exemption_regions on exemption.id=exemption_regions.exemption_id where exemption.account_id=#{accountId}
<if test="exemptionId!=null"> and exemption.id=#{exemptionId}
</if> <if test="customerId!=null"> and exemption.customer_id=#{customerId}
</if> order by id limit 0,#{maxCount} </select>
I can't understand the error message "The content of element type "association" must match "(constructor?,id*,result*,association*,collection*,discriminator?)",so I don't know how to fix it!!
This is my first time to use typeAliases feature,I am not sure if my configuration is right or wrong? Thanks in advance. 陈抒 Best regards http://blog.csdn.net/sheismylife |
|
It seems that there is something wrong in my users.map.xml file.Who can help me?
陈抒 Best regards http://blog.csdn.net/sheismylife On Sun, Nov 28, 2010 at 7:47 PM, 陈抒 <[hidden email]> wrote:
|
|
I don't know why association can't include another association,because in the ibatis-3-mapper.dtd file,it allows this usage.Please correct me if I am wrong. <!ELEMENT association (constructor?,id*,result*,association*,collection*, discriminator?)>
<!ATTLIST association property CDATA #REQUIRED column CDATA #IMPLIED javaType CDATA #IMPLIED jdbcType CDATA #IMPLIED select CDATA #IMPLIED resultMap CDATA #IMPLIED
typeHandler CDATA #IMPLIED > I have to update my xml file,there is no validation error now. <resultMap id="federalIdMap" type="FederalIdType">
<id property="federalId" column="federal_id" javaType="FederalIdClassificationType" jdbcType="VARCHAR"/> <result property="federalIdType" column="federal_id_type"/>
</resultMap> <resultMap id="exemptionMap" type="ExemptionType"> <id property="exemptionId" column="exemption_id"/>
<association property="exemptionCustomer" column="customer_id" javaType="ExemptCustomerType" resultMap="customerMap"/> <collection property="exemptionRegions" ofType="ExemptRegionType">
<result property="country" column="country_code"/> <result property="stateOrProvince" column="state_code"/> <result property="reason" column="reason_code"/>
<result property="taxOrPermitId" column="permit_id"/> <result property="startDate" column="start_date" javaType="java.util.Date" jdbcType="INTEGER"/>
<result property="endDate" column="end_date" javaType="java.util.Date" jdbcType="INTEGER"/> </collection> </resultMap> <resultMap id="exemptionRecordMap" type="ExemptionRecord"> <result property="accountId" column="account_id"/> <association property="exemption" column="exemption_id" javaType="ExemptionType" resultMap="exemptionMap"/>
</resultMap> <resultMap id="customerMap" type="ExemptCustomerType"> <id property="customerId" column="customer_id"/>
<result property="customerName" column="customer_name"/> <result property="street1" column="address1"/> <result property="street2" column="address2"/>
<result property="city" column="city"/> <result property="stateOrProvince" column="state"/> <result property="postalCode" column="zipcode"/>
<result property="telephoneNumber" column="phone_number"/> <result property="emailAddress" column="email"/> <result property="status" column="active" javaType="ExemptionStatusType" jdbcType="INTEGER"/>
<result property="country" column="country"/> <association property="federalId" column="federal_id" javaType="FederalIdType" resultMap="federalIdMap"/>
</resultMap> Also,if I put the assocation in front of one result element in my customerMap as follows,I got validation error.It's confusing me! <resultMap id="customerMap" type="ExemptCustomerType">
<id property="customerId" column="customer_id"/> <result property="customerName" column="customer_name"/> <result property="street1" column="address1"/>
<result property="street2" column="address2"/> <result property="city" column="city"/> <result property="stateOrProvince" column="state"/>
<result property="postalCode" column="zipcode"/> <result property="telephoneNumber" column="phone_number"/> <result property="emailAddress" column="email"/>
<result property="status" column="active" javaType="ExemptionStatusType" jdbcType="INTEGER"/> <association property="federalId" column="federal_id" javaType="FederalIdType" resultMap="federalIdMap"/>
<result property="country" column="country"/> </resultMap>
$ xmllint --valid --noout --dtdvalid ./ibatis-3-mapper.dtd ./user.map.xml ./user.map.xml:53: element resultMap: validity error : Element resultMap content does not follow the DTD, expecting (constructor? , id* , result* , association* , collection* , discriminator?), got (id result result result result result result result result result association result )
</resultMap> ^ ./user.map.xml:40: element resultMap: validity error : Element resultMap content does not follow the DTD, expecting (constructor? , id* , result* , association* , collection* , discriminator?), got (id result result result result result result result result result association result )
Document ./user.map.xml does not validate against ./ibatis-3-mapper.dtd After digging into this problem,I found a XML validation tool is very required,that will make my life easier.My tool is from http://www.xmlsoft.org/xmldtd.html.
陈抒 Best regards http://blog.csdn.net/sheismylife On Sun, Nov 28, 2010 at 8:24 PM, 陈抒 <[hidden email]> wrote: It seems that there is something wrong in my users.map.xml file.Who can help me? |
|
In reply to this post by 陈抒
for this part,
<association property="ExemptionCustomer" column="customer_id" javaType="ExemptCustomerType">
<id property="customerId" column="customer_id" /> <result property="customerName" column="customer_name" />
<result property="street1" column="address1" /> <result property="street2" column="address2" />
<result property="city" column="city" /> <result property="stateOrProvince" column="state" />
<result property="postalCode" column="zipcode" /> <result property="phoneNumber" column="phone_number" />
<result property="email" column="email" /> <result property="active" column="active" javaType="ExemptionStatusType" jdbcType="INTEGER"/>
<result property="country" column="country" /> <association property="federalId" column="federal_id" javaType="FederalIdType">
<id property="federalId" column="federal_id" javaType="FederalIdClassificationType" jdbcType="VARCHAR"/>
<result property="federalIdType" column="federal_id_type"/>
</association> </association>
can you try modify as above? Jackie On Sun, Nov 28, 2010 at 19:47, 陈抒 <[hidden email]> wrote:
|
|
Thanks for your reply. I don't know what's the use of column="customer_id".From my view,this attribute is useless.Please correct me if I am wrong. About the order of association sub-element,yes,I have change its order in my latest mail.Did see that?
<resultMap id="customerMap" type="ExemptCustomerType"> <id property="customerId" column="customer_id"/> <result property="customerName" column="customer_name"/>
<result property="street1" column="address1"/> <result property="street2" column="address2"/> <result property="city" column="city"/>
<result property="stateOrProvince" column="state"/> <result property="postalCode" column="zipcode"/> <result property="telephoneNumber" column="phone_number"/>
<result property="emailAddress" column="email"/> <result property="status" column="active" javaType="ExemptionStatusType" jdbcType="INTEGER"/>
<result property="country" column="country"/> <association property="federalId" column="federal_id" javaType="FederalIdType" resultMap="federalIdMap"/>
</resultMap> I am new to DTD validation,does the following rule means the association sub-element must be behind the result sub-element? <!ELEMENT association (constructor?,id*,result*,association*,collection*, discriminator?)>
About 陈抒 Best regards http://blog.csdn.net/sheismylife On Mon, Nov 29, 2010 at 11:11 AM, lwpro <[hidden email]> wrote: for this part, |
|
This post has NOT been accepted by the mailing list yet.
I was getting this error on my first try at creating a new ResultMap in an existing (working) configuration. Changing it so that all the results preceded all the associations got rid of the error.
|
| Powered by Nabble | Edit this page |
