ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Poitras Christian" <Christian.Poit...@ircm.qc.ca>
Subject RE: Problem accessing a HashMap
Date Mon, 10 Sep 2007 16:25:22 GMT
I doubt iBATIS can do that. Iterate tag cannot iterate over keys as far
as I know. And I doubt you can write #map(key).id#
This is why I recommend using a List of Maps.

For instance, you could put the customer in a Map ("customer" key). It's
product and the other columns can put put in a Map (creating a List of
Map). Put the List in the customer Map ("products" key).
Then, the resulting xml would look like this.
<insert id="insertCustomerProductRel" parameterClass="CustomerDTO">
		INSERT INTO PLC.CUSTOMER_PRODUCT_REL (CUSTOMER_ID,
PRODUCT_ID, OTHER_COLUMN)
		VALUES 
		<iterate property="products" conjunction=",">
	
(#customer.id#,#productList[].product.id#,#productList[].otherPropertyIn
Map#)
		</iterate>
</insert>

Christian

-----Original Message-----
From: PLC_David [mailto:spaceman2k4@gmx.de] 
Sent: Monday, 10 September 2007 12:18
To: user-java@ibatis.apache.org
Subject: RE: Problem accessing a HashMap


How I can use the key and the value from this map ?

Example:  HashMap<Object, Integer> 

I have to iterate over all elements of the map, but I need the key AND
the value !

I need something like this: (#id#,#products.key#,#products.value#)  

David




Poitras Christian wrote:
> 
> It would be easier with a List of Maps.
> 
> Put the information in the Map and plug this kind of code.
> <insert id="insertCustomerProductRel" parameterClass="CustomerDTO">
> 		INSERT INTO PLC.CUSTOMER_PRODUCT_REL (CUSTOMER_ID,
> PRODUCT_ID)
> 		VALUES 
> 		<iterate property="products" conjunction=",">
> 	
> (#id#,#products[].propertyInMap#,#products[].otherPropertyInMap#)
> 		</iterate>
> </insert>
>  
> Christian
> 
> 
> -----Original Message-----
> From: PLC_David [mailto:spaceman2k4@gmx.de]
> Sent: Monday, 10 September 2007 10:08
> To: user-java@ibatis.apache.org
> Subject: Problem accessing a HashMap
> 
> 
> Originally I had a java.util.List in my Java code to present an 
> unidirectional one-to-many relation which is a many-to-many relation 
> in the database. This is a customer that could have multiple products.
> Now I need a java.util.HashMap instead of the list where the elements 
> of the old list are the new keys while the values represent an 
> additional attribute. The additional value (value of Map) should be 
> saved in a new column in the existing relation table.
> 
> 
> The old mapping with list:
> 
> <insert id="insertCustomerProductRel" parameterClass="CustomerDTO">
> 		INSERT INTO PLC.CUSTOMER_PRODUCT_REL (CUSTOMER_ID,
> PRODUCT_ID)
> 		VALUES 
> 		<iterate property="products" conjunction=",">
> 		(#id#,#products[].id#)
> 		</iterate>
> </insert>
> 
> My question is how I can access the key and the value of this map. So 
> far I received this exception:
> 
> The error occurred in ibatis/Mapping.xml.  
> --- The error occurred while preparing the mapped statement for 
> execution.
> --- Check the insertCustomerProductRel.  
> --- Check the parameter map.  
> Cause: com.ibatis.sqlmap.client.SqlMapException: ParameterObject or 
> property was not a Collection, Array or Iterator.
> 
> I hope somebody can help me.
> 
> --
> View this message in context:
> http://www.nabble.com/Problem-accessing-a-HashMap-tf4414963.html#a1259
> 35
> 47
> Sent from the iBATIS - User - Java mailing list archive at Nabble.com.
> 
> 
> 

--
View this message in context:
http://www.nabble.com/Problem-accessing-a-HashMap-tf4414963.html#a125968
49
Sent from the iBATIS - User - Java mailing list archive at Nabble.com.


Mime
View raw message