Hi guys,
Is it possible to do type conversion in iBatis, such that a particular object say for example a Price object can be persisted in two columns. Eg.
public class Price {
private String amount;
private String currencyType;
.... // getter/ setter
}
public class Item {
private String id;
private String itemName;
private Price price;
// getter/setter
}
<resultMap id="result_item">
<result proprety="id" column="ID" ..../>
<result property="itemName" column="ITEM_NAME" />
<result property="price" typeHandler="......" />
</resultMap>
<statement .... resultMap="result_item".>
SELECT
i.id as ID,
i.itemName as ITEM_NAME,
i.currencyType as CURRENCY_TYPE,
i.amount as AMOUNT
FROM
item as i
</statement>
1] The typeHandler java class, if not mistaken it should either extends off TypeHandlerCallback interface or TypeHandler, is this correct? Can't seems to find it int the docs, or did I just missed it.
2] From the TypeHandlerCallback and TypeHandler interface, it looks like they are more towards a 1 to 1 conversion between the java object property and DB column. say, it would be possible to 'YES'/'NO' string to a boolean column type. Is it possible to convert say 'USD1.00' or maybe 'AUD2.00' to two columns in the db say USD in a column and 1.00 in the other?
Thanks a lot. :-)
regards
Is it possible to do type conversion in iBatis, such that a particular object say for example a Price object can be persisted in two columns. Eg.
public class Price {
private String amount;
private String currencyType;
.... // getter/ setter
}
public class Item {
private String id;
private String itemName;
private Price price;
// getter/setter
}
<resultMap id="result_item">
<result proprety="id" column="ID" ..../>
<result property="itemName" column="ITEM_NAME" />
<result property="price" typeHandler="......" />
</resultMap>
<statement .... resultMap="result_item".>
SELECT
i.id as ID,
i.itemName as ITEM_NAME,
i.currencyType as CURRENCY_TYPE,
i.amount as AMOUNT
FROM
item as i
</statement>
1] The typeHandler java class, if not mistaken it should either extends off TypeHandlerCallback interface or TypeHandler, is this correct? Can't seems to find it int the docs, or did I just missed it.
2] From the TypeHandlerCallback and TypeHandler interface, it looks like they are more towards a 1 to 1 conversion between the java object property and DB column. say, it would be possible to 'YES'/'NO' string to a boolean column type. Is it possible to convert say 'USD1.00' or maybe 'AUD2.00' to two columns in the db say USD in a column and 1.00 in the other?
Thanks a lot. :-)
regards
