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