ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Clinton Begin <clinton.be...@gmail.com>
Subject Re: Avoiding N+1 with complex HashMap properties.
Date Fri, 10 Dec 2004 15:08:44 GMT
Tough call.  Some people want it stored as a single property (e.g.
imagine the key is a classname), and others want it stored nested.

Currently, as you've discovered, it's not nested.

I would suggest that if you have a complex object model, then you
should model it using JavaBeans.  Maps are very loose, unpredictable
and limited.

Cheers,
Clinton


On Fri, 10 Dec 2004 10:03:16 -0500, Jerome Jacobsen
<jerome.jacobsen@gentootech.com> wrote:
> Hello,
> 
> I'm using SQL Maps 2.08.  I was hoping I could do the following
> but I get a ProbeException.  Should this be supported?
> 
> <resultMap id="get-customer-period-result"
>            class="java.util.HashMap">
>   <result property="customerNum"
>           column="CUSTOMER_NUMBER"
>           columnIndex="1"/>
>   <result property="category.id"
>           column="CATEGORY_ID"
>           columnIndex="2"/>
>   <result property="category.parentId"
>           column="PARENT_CATEGORY_ID"
>           columnIndex="3"/>
>   <result property="category.description"
>           column="CATEGORY_DESC"
>           columnIndex="4"/>
>   ...
> </resultMap>
> 
> <statement id="getCustomerPeriodSummary"
>            resultMap="get-customer-period-result">
>   SELECT CPS.CUSTOMER_NUMBER,
>          PC.CATEGORY_ID,
>          PC.PARENT_CATEGORY_ID,
>          PC.DESCRIPTION AS CATEGORY_DESC,
>          PC.SEQUENCE AS CATEGORY_SEQUENCE,
>          ...
>     FROM CUSTOMER_PERIOD_SUMMARY CPS, PRODUCT_CATEGORY PC, SALES_PERIOD SP
>    WHERE CPS.CUSTOMER_NUMBER = #value#
>      AND CPS.CATEGORY_ID = PC.CATEGORY_ID
>      AND CPS.PERIOD_ID = SP.PERIOD_ID
> ORDER BY CATEGORY_SEQUENCE
> </statement>
> 
> I was hoping that sqlmaps would store the 'category.id',
> 'category.parentId', 'category.description' either in a nested
> HashMap (key of 'category') or store the values in the top
> level HashMap with those keys ('category.id', etc.)
> 
> However neither case appears to happen and I get the
> exception below.  I realize that I can map the complex
> properties with separate selects but I want to avoid the
> N+1 query problem.  So I do the join instead.
> 
> com.ibatis.common.beans.ProbeException: There is no WRITEABLE property named
> 'id' in class 'java.lang.Object'
>         at com.ibatis.common.beans.ClassInfo.getSetter(ClassInfo.java:146)
>         at
> com.ibatis.common.beans.ComplexBeanProbe.setProperty(ComplexBeanProbe.java:3
> 34)
>         at
> com.ibatis.common.beans.ComplexBeanProbe.setObject(ComplexBeanProbe.java:231
> )
>         at com.ibatis.common.beans.GenericProbe.setObject(GenericProbe.java:69)
>         at
> com.ibatis.sqlmap.engine.exchange.ComplexDataExchange.setData(ComplexDataExc
> hange.java:87)
>         at
> com.ibatis.sqlmap.engine.mapping.result.BasicResultMap.setResultObjectValues
> (BasicResultMap.java:231)
>         at
> com.ibatis.sqlmap.engine.mapping.statement.RowHandlerCallback.handleResultOb
> ject(RowHandlerCallback.java:63)
>         at
> com.ibatis.sqlmap.engine.execution.SqlExecutor.handleResults(SqlExecutor.jav
> a:350)
>         at
> com.ibatis.sqlmap.engine.execution.SqlExecutor.executeQuery(SqlExecutor.java
> :179)
>         at
> com.ibatis.sqlmap.engine.mapping.statement.GeneralStatement.sqlExecuteQuery(
> GeneralStatement.java:200)
>         at
> com.ibatis.sqlmap.engine.mapping.statement.GeneralStatement.executeQueryWith
> Callback(GeneralStatement.java:168)
>         at
> com.ibatis.sqlmap.engine.mapping.statement.GeneralStatement.executeQueryForL
> ist(GeneralStatement.java:118)
>         at
> com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate.queryForList(SqlMapExec
> utorDelegate.java:626)
>         at
> com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate.queryForList(SqlMapExec
> utorDelegate.java:598)
>         at
> com.ibatis.sqlmap.engine.impl.SqlMapSessionImpl.queryForList(SqlMapSessionIm
> pl.java:107)
>         at
> org.springframework.orm.ibatis.SqlMapClientTemplate$3.doInSqlMapClient(SqlMa
> pClientTemplate.java:202)
>         at
> org.springframework.orm.ibatis.SqlMapClientTemplate.execute(SqlMapClientTemp
> late.java:142)
>         at
> org.springframework.orm.ibatis.SqlMapClientTemplate.executeWithListResult(Sq
> lMapClientTemplate.java:164)
>         at
> org.springframework.orm.ibatis.SqlMapClientTemplate.queryForList(SqlMapClien
> tTemplate.java:200)
>         at
> com.giv.dashboard.dao.db.ibatis.SqlMapSalesStatisticsDAO.getCategoryStatsFor
> Customer(SqlMapSalesStatisticsDAO.java:28)
>         at
> com.giv.dashboard.DashboardImpl.getCategorySummaries(DashboardImpl.java:42)
>         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:324)
>         at
> org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopU
> tils.java:295)
>         at
> org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint
> (ReflectiveMethodInvocation.java:154)
>         at
> org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(Reflect
> iveMethodInvocation.java:121)
>         at
> org.springframework.transaction.interceptor.TransactionInterceptor.invoke(Tr
> ansactionInterceptor.java:56)
>         at
> org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(Reflect
> iveMethodInvocation.java:143)
>         at
> org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopPro
> xy.java:174)
>         at $Proxy0.getCategorySummaries(Unknown Source)
>         at
> com.giv.dashboard.web.spring.ViewCategoriesController.handleRequestInternal(
> ViewCategoriesController.java:62)
>         at
> org.springframework.web.servlet.mvc.AbstractController.handleRequest(Abstrac
> tController.java:128)
>         at
> org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter.handle(Si
> mpleControllerHandlerAdapter.java:44)
>         at
> org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServle
> t.java:532)
>         at
> org.springframework.web.servlet.FrameworkServlet.serviceWrapper(FrameworkSer
> vlet.java:366)
>         at
> org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java
> :317)
>         at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)
>         at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
>         at
> com.evermind.server.http.ResourceFilterChain.doFilter(ResourceFilterChain.ja
> va:65)
>         at oracle.security.jazn.oc4j.JAZNFilter.doFilter(Unknown Source)
>         at
> com.evermind.server.http.ServletRequestDispatcher.invoke(ServletRequestDispa
> tcher.java:604)
>         at
> com.evermind.server.http.ServletRequestDispatcher.forwardInternal(ServletReq
> uestDispatcher.java:317)
>         at
> com.evermind.server.http.HttpRequestHandler.processRequest(HttpRequestHandle
> r.java:790)
>         at
> com.evermind.server.http.HttpRequestHandler.run(HttpRequestHandler.java:270)
>         at
> com.evermind.server.http.HttpRequestHandler.run(HttpRequestHandler.java:112)
>         at
> com.evermind.util.ReleasableResourcePooledExecutor$MyWorker.run(ReleasableRe
> sourcePooledExecutor.java:192)
>         at java.lang.Thread.run(Thread.java:534)
> 
>

Mime
View raw message