[ https://issues.apache.org/jira/browse/IBATIS-483?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12729658#action_12729658 ]
aaron pieper commented on IBATIS-483: ------------------------------------- I was able to fix this issue by changing how the SqlMapClientTemplate was configured in Spring. In iBatis 2.1.7, it was OK to configure the SqlMapClientTemplate this way: <bean class="org.springframework.orm.ibatis.SqlMapClientTemplate"> <property name="sqlMapClient"> <bean class="org.springframework.orm.ibatis.SqlMapClientFactoryBean"/> ... </bean> </property> <property name="dataSource" ref="dataSource"/> </bean> However, starting in iBatis 2.3.4, we got errors unless we configure the SqlMapClientTemplate this way: <bean class="org.springframework.orm.ibatis.SqlMapClientTemplate"> <property name="sqlMapClient"> <bean class="org.springframework.orm.ibatis.SqlMapClientFactoryBean"/> <property name="dataSource" ref="dataSource"/> ... </bean> </property> </bean> In other words, if you don't declare a datasource on the SqlMapClientFactoryBean, the SqlMapClient has a null transaction manager, which causes problems in some causes. > Empty/Null resultset from subselect causes NPE > ---------------------------------------------- > > Key: IBATIS-483 > URL: https://issues.apache.org/jira/browse/IBATIS-483 > Project: iBatis for Java > Issue Type: Bug > Components: SQL Maps > Affects Versions: 2.3.2, 2.3.3, 2.3.4 > Environment: Ubuntu Linux, Tomcat 5/6, MySQL > Reporter: John Crawford > Fix For: 2.3.5 > > Attachments: ibatis-npe.txt > > > When doing a subselect (using maps), I get a NPE when the result of the > subselect is null/empty. I believe that this occurs in every version since > 2.1.7, but unfortunately, I have to stick with 2.1.7 because of this issue. > (And, of course, the maven repos only have 2.3, so I have to do an annoying > workaround for it) > Example Code: (Issue is with the lineItems mapping from the first resultMap) > <resultMap class="com.acp.beans.OrderCart" id="cartBean"> > <result property="id" column="cart_id"/> > <result property="orderId" column="order_id" nullValue="-1"/> > <result property="lineItems" column="cart_id" > select="getLineItems"/> > <result property="user" column="user_id" select="getUserById"/> > <result property="created" column="create_dt"/> > </resultMap> > <resultMap class="com.acp.beans.OrderItems" id="lineItemsBean"> > <result property="id" column="order_item_id" /> > <result property="cartId" column="cart_id"/> > <result property="quantity" column="quantity"/> > <result property="orderPictureBean" column="picture_id" > select="getOrderPictures"/> > <result property="pictureSize.id" column="picture_size_id"/> > <result property="pictureSize.title" > column="picture_size_title"/> > <result property="pictureSize.cost" column="picture_size_cost"/> > <result property="pictureSize.pictureUrl" > column="picture_size_link_url_th"/> > <result property="pictureType.id" column="picture_type_id"/> > <result property="pictureType.title" > column="picture_type_title"/> > <result property="pictureType.cost" column="picture_type_cost"/> > </resultMap> > <select id="getLineItems" parameterClass="java.lang.Integer" > resultMap="lineItemsBean"> > SELECT > OI.cart_id, > OI.order_item_id, > OI.quantity, > OI.picture_id, > OI.picture_size as picture_size_id, > PS.title AS picture_size_title, > PS.cost AS picture_size_cost, > PS.link_url_th AS picture_size_link_url_th, > OI.picture_type as picture_type_id, > PT.title AS picture_type_title, > PT.cost AS picture_type_cost > FROM > tb_OrderItem OI > JOIN tb_PictureSize PS on PS.picture_size_id = > OI.picture_size > JOIN tb_PictureType PT on PT.picture_type_id = > OI.picture_type > WHERE > OI.cart_id = #cart_id# > </select> -- This message is automatically generated by JIRA. - You can reply to this email to add a comment to the issue online. --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@ibatis.apache.org For additional commands, e-mail: dev-h...@ibatis.apache.org