ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Dodo" <j2eed...@gmail.com>
Subject TypeHandlerCallback problem
Date Sat, 08 Jul 2006 03:45:08 GMT
Hi,

If I have an Item.java class that has a complex object
, MonetaryAmount.java as its field. Now for security reason,
fields of MonetaryAmount class has private final fields and 
getter methods only, setter methods are empty.

Now you can see I have problem using TypeHandlerCallback
to return MonetaryAmount's private final field as setter
method for Currency needs to be empty 

E.g.

public class Item {

 private Monetary initialPrice;
 
 // setter and getter for initialPrice
 ....

}

  and 

public class MonetaryAmount implements Serializable {

 private final BigDecimal value;
 private final Currency currency;

 public MonetaryAmount(BigDecimal value, Currency currency) {
  this.value = value;
  this.currency = currency;
 }

 public Currency getCurrency() {
  return currency;
 }

 public BigDecimal getValue() {
  return value;
 }
    .........

 public void setCurrency(Currency currency) {
 }

 public void setValue(BigDecimal value) {
 }

}

so mapping file will look like

 <typeAlias alias="item" type="org.auctionfuse.model.Item"/>

    <resultMap id="itemResult" class="item">
        <result property="id" column="item_id"/>
  ..
  <!-- initialPrice is MonetaryAmount field -->
        <result property="initialPrice.value" column="initial_price"/>  
        <result property="initialPrice.currency" column="currency"
         typeHandler= "org.auctionfuse.ibatis.typehandler.CurrencyTypeHandler" />  
  ...    
    </resultMap>

where CurrencyTypeHandler implements TypeHandlerCallback and tries to converts
string retrieved from database to Currency object

but the problem is setter methods of MonetaryAmount.java simply does nothing

I was wandering if anyone has elegant solution in iBatis.

Thanks,

Sam
Mime
View raw message