ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Gordon Ross" <G.R...@ccw.gov.uk>
Subject How to support read-only fields/paramters
Date Mon, 07 May 2007 07:23:55 GMT
(This may not be totally iBatis realated, I'm not sure. Feel free to
point me elsewhere)

Often when working with objects, you have fields that should never be
changed (e.g. an "id" field which is generated by the database). The
usual way (as I understand it) that you achieve this, is to specify the
parameter value in the objects constructor, and only provide a get()
method, with no corresponding set() method (or a final private one so
that it can't be over-ridden)

However, iBatis does not use the parmaterised constructor to build an
object. Instead, it uses the null constructor, and then calls the
individual set() methods - which have to be public for iBatis to be able
to call them. This means that anyone could call the set() method and
change the value.

There are two ways that I can see to achieve this:

1) Only allow the set() method to be called once. (Use some internal
boolean flag to see if it the set() method has been called before)

2) Somehow configure/change iBatis so that it would use the constructor
to set the request fields.

Anyone got any thoughts or comments on this ?

Thanks,

GTG

Gordon Ross,
Network Manager/Rheolwr Rhydwaith
Countryside Council for Wales/Cyngor Cefn Gwlad Cymru

Mime
View raw message