Thank you Niels, I'll try what you say.
About your question, according to the user guide, this feature (one resultmap refering to another in 1-1 and 1-N) is only in 2.2.0, so I didn't test it until this version was released.

On 8/16/06, Niels Beekman <[EMAIL PROTECTED]> wrote:

I think you should use the fully qualified name of the resultmap, so User.countryResult shoulud work just fine. Does this behaviour occur only with 2.2.0 or did you just mention it to be complete?

 

Niels

 


From: Javier Urbaneja [mailto:[EMAIL PROTECTED]]
Sent: woensdag 16 augustus 2006 14:03
To: [email protected]
Subject: Problem with Multiple resultmaps in 2.2.0

 

This is my map file User.xml:

<sqlMap namespace="User">

  <resultMap class="es.como.jtp.domain.User" id="userResult">
    <result property="idUser"              column="ID_USER"               jdbcType="INTEGER"  javaType="int"/>
    <result property="country"             resultMap="countryResult"/>
    <result property="city"                column="CITY"                  jdbcType="VARCHAR"  javaType="string"/>
    <result property="givenName"           column="GIVEN_NAME"            jdbcType="VARCHAR"  javaType="string"/>
    <result property="firstSurname"        column="FIRST_SURNAME"         jdbcType="VARCHAR"  javaType="string"/>
    <result property="secondSurname"       column="SECOND_SURNAME"        jdbcType="VARCHAR"  javaType="string"/>
    <result property="dateOfBirth"         column="DATE_OF_BIRTH"         jdbcType="DATE"     javaType="date"/>
    <result property="email"               column="EMAIL"                 jdbcType="VARCHAR"  javaType="string"/>
    <result property="nickname"            column="NICKNAME"              jdbcType="VARCHAR"  javaType="string"/>
    <result property="address"             column="ADDRESS"               jdbcType="VARCHAR"  javaType="string"/>
    <result property="town"                column="TOWN"                  jdbcType="VARCHAR"  javaType="string"/>
    <result property="zip"                 column="ZIP"                   jdbcType="INTEGER"  javaType="int"       nullValue="0"/>
    <result property="lastLoginDate"       column="LAST_LOGIN_DATE"       jdbcType="DATE"     javaType="date"/>
    <result property="registerDate"        column="REGISTER_DATE"         jdbcType="DATE"     javaType="date"/>
    <result property="password"            column="PASSWORD"              jdbcType="VARCHAR"  javaType="string"/>
    <result property="gender"              column="GENDER"                jdbcType="VARCHAR"  javaType="string"/>
    <result property="homePhoneNumber"     column="HOME_PHONE_NUMBER"     jdbcType="VARCHAR"  javaType="string"/>
    <result property="mobilePhoneNumber"   column="MOBILE_PHONE_NUMBER"   jdbcType="VARCHAR"  javaType="string"/>
    <result property="documentNumber"      column="DOCUMENT_NUMBER"       jdbcType="VARCHAR"  javaType="string"/>
    <result property="active"              column="ACTIVE"                jdbcType="INTEGER"  javaType="boolean"   nullValue="false"/>
    <result property="confirmed"           column="CONFIRMED"             jdbcType="INTEGER"  javaType="boolean"   nullValue="false"/>
    <result property="karma"               column="KARMA"                 jdbcType="INTEGER"  javaType="int"       nullValue="0"/>
    <result property="points"              column="POINTS"                jdbcType="INTEGER"  javaType="int"       nullValue="0"/>
    <result property="success"             column="SUCCESS"               jdbcType="INTEGER"  javaType="int"       nullValue="0"/>
  </resultMap>
 
  <resultMap class="es.como.jtp.domain.Country" id="countryResult">
    <result property="idCountry" column="ID_COUNTRY" jdbcType="INTEGER" javaType="int"/>
    <result property="name" column="COUNTRY" jdbcType="VARCHAR" javaType="string"/>
  </resultMap>

  <insert id="registerUser" parameterClass=" es.como.jtp.domain.User">
    <selectKey keyProperty="idUser" resultClass="int">
      select user_register_seq.nextval as idUser from dual
    </selectKey>
    insert into users (id_user, nickname, password, email, id_country)
    values (#idUser:INTEGER#, #nickname:VARCHAR#, #password:VARCHAR#, #email:VARCHAR#, 1)
  </insert>
    
  <select id="getUserByNickname" resultMap="userResult" parameterClass="string">
    select * from users,countries where users.id_country = countries.id_country and nickname = #value#
  </select>
</sqlMap>


And this is stack after invoking the select getUserByNickname:

Stack

    org.apache.struts.beanaction.BeanActionException: Error dispatching bean action via URL pattern ('registerUser').  Cause: org.apache.struts.beanaction.BeanActionException
: Error invoking Action.  Cause: java.lang.reflect.InvocationTargetException

        at org.apache.struts.beanaction.BeanAction.execute(BeanAction.java:249)
        at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:419)
        at org.apache.struts.action.RequestProcessor.process
(RequestProcessor.java:224)
        at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1194)
        at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432)
        at javax.servlet.http.HttpServlet.service
(HttpServlet.java:709)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter
(ApplicationFilterChain.java:173)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
        at
org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:432)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
        at org.apache.catalina.valves.ErrorReportValve.invoke
(ErrorReportValve.java:105)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
        at org.apache.coyote.http11.Http11Processor.process
(Http11Processor.java:869)
        at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:664)
        at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java
:527)
        at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)
        at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
        at java.lang.Thread.run
(Thread.java:595)
Caused by: org.apache.struts.beanaction.BeanActionException: Error invoking Action.  Cause: java.lang.reflect.InvocationTargetException
        at org.apache.struts.beanaction.ActionInvoker.invoke(ActionInvoker.java
:18)
        at org.apache.struts.beanaction.DefaultActionInterceptor.intercept(DefaultActionInterceptor.java:5)
        at org.apache.struts.beanaction.BeanAction.execute(BeanAction.java:246)
        ... 21 more
Caused by: java.lang.reflect.InvocationTargetException

        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:585)
        at org.apache.struts.beanaction.ActionInvoker.invoke(ActionInvoker.java:16)
        ... 23 more
Caused by: org.apache.struts.beanaction.BeanActionException: There was a problem creating your Account Information.  Cause:
com.ibatis.dao.client.DaoException
: Failed to execute queryForObject - id [getUserByNickname], parameterObject [mira].  Cause: com.ibatis.common.jdbc.exception.NestedSQLException:   
--- The error occurred in es/como/jtp/persistence/sqlmapdao/sql/User.xml. 

--- The error occurred while applying a result map. 
--- Check the User.userResult. 
--- The error happened while setting a property on the result object. 
--- Cause: com.ibatis.sqlmap.client.SqlMapException
: There is no result map named countryResult in this SqlMap.
Caused by: com.ibatis.sqlmap.client.SqlMapException: There is no result map named countryResult in this SqlMap.
        at es.como.jtp.presentation.UserBean.registerUser
(UserBean.java:129)
        ... 28 more
Caused by: com.ibatis.dao.client.DaoException: Failed to execute queryForObject - id [getUserByNickname], parameterObject [mira].  Cause: com.ibatis.common.jdbc.exception.NestedSQLException

:   
--- The error occurred in es/como/jtp/persistence/sqlmapdao/sql/User.xml. 
--- The error occurred while applying a result map. 
--- Check the User.userResult. 
--- The error happened while setting a property on the result object. 

--- Cause: com.ibatis.sqlmap.client.SqlMapException: There is no result map named countryResult in this SqlMap.
Caused by: com.ibatis.sqlmap.client.SqlMapException: There is no result map named countryResult in this SqlMap.

        at com.ibatis.dao.client.template.SqlMapDaoTemplate.queryForObject(SqlMapDaoTemplate.java:225)
        at es.como.jtp.persistence.sqlmapdao.UserSqlMapDao.getUser(UserSqlMapDao.java:15)
        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:585)
        at com.ibatis.dao.engine.impl.DaoProxy.invoke(DaoProxy.java:72)
        at $Proxy0.getUser(Unknown Source)
        at es.como.jtp.service.UserService.getUser(UserService.java:22)
        at es.como.jtp.presentation.UserBean.registerUser
(UserBean.java:124)
        ... 28 more
Caused by: com.ibatis.common.jdbc.exception.NestedSQLException:  
--- The error occurred in es/como/jtp/persistence/sqlmapdao/sql/User.xml. 
--- The error occurred while applying a result map. 

--- Check the User.userResult. 
--- The error happened while setting a property on the result object. 
--- Cause: com.ibatis.sqlmap.client.SqlMapException: There is no result map named countryResult in this SqlMap.

Caused by: com.ibatis.sqlmap.client.SqlMapException: There is no result map named countryResult in this SqlMap.
        at com.ibatis.sqlmap.engine.mapping.statement.GeneralStatement.executeQueryWithCallback(GeneralStatement.java
:188)
        at com.ibatis.sqlmap.engine.mapping.statement.GeneralStatement.executeQueryForObject(GeneralStatement.java:104)
        at com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate.queryForObject(SqlMapExecutorDelegate.java
:565)
        at com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate.queryForObject(SqlMapExecutorDelegate.java:540)
        at com.ibatis.sqlmap.engine.impl.SqlMapSessionImpl.queryForObject(SqlMapSessionImpl.java:106)
        at com.ibatis.sqlmap.engine.impl.SqlMapClientImpl.queryForObject
(SqlMapClientImpl.java:84)
        at com.ibatis.dao.client.template.SqlMapDaoTemplate.queryForObject(SqlMapDaoTemplate.java:223)
        ... 37 more
Caused by: com.ibatis.sqlmap.client.SqlMapException: There is no result map named countryResult in this SqlMap.

        at com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate.getResultMap(SqlMapExecutorDelegate.java:356)
        at com.ibatis.sqlmap.engine.mapping.result.BasicResultMap.setNestedResultMappingValue(BasicResultMap.java:420)

        at com.ibatis.sqlmap.engine.mapping.result.BasicResultMap.applyNestedResultMap(BasicResultMap.java:396)
        at com.ibatis.sqlmap.engine.mapping.result.BasicResultMap.setResultObjectValues(BasicResultMap.java:382)

        at com.ibatis.sqlmap.engine.mapping.statement.RowHandlerCallback.handleResultObject(RowHandlerCallback.java:64)
        at com.ibatis.sqlmap.engine.execution.SqlExecutor.handleResults(SqlExecutor.java:376)
        at com.ibatis.sqlmap.engine.execution.SqlExecutor.handleMultipleResults
(SqlExecutor.java:295)
        at com.ibatis.sqlmap.engine.execution.SqlExecutor.executeQuery(SqlExecutor.java:186)
        at com.ibatis.sqlmap.engine.mapping.statement.GeneralStatement.sqlExecuteQuery(GeneralStatement.java:205)

        at com.ibatis.sqlmap.engine.mapping.statement.GeneralStatement.executeQueryWithCallback(GeneralStatement.java:173)
        ... 43 more

 

If I "inline" the country resultmap (like before 2.2.0) by commenting out:
<!-- <result property="country"             resultMap="countryResult"/> -->
and adding:
<result property="country.idCountry"   column="ID_COUNTRY"            jdbcType="INTEGER"  javaType="int"/>
<result property="country.name"        column="COUNTRY"               jdbcType="VARCHAR"  javaType="string"/>
then it works perfectly.

Greetings and thank you.



Reply via email to