|
And there I found the
problem, in the default constructor. I was so focussed on the
resulting exception by iBatis that I lost sight of the fact that there is an
base class that does some initialisation. Which in turns uses some of the
properties to set there default values… which results in the exception
being throwed ;) Ok, I am going to hear my
colleagues about this for a long time to come ;) The snippet, public string Username { get { return username; } set { if (value != null || value.Length > 0) { username
= value; } else { throw new AttributeFormatException(ErrorCodes.FIELDCANNOTBENULLERROR); } } } This is rather crude way
to check if an valid value is being used. Eventually we are going
to use Custom attributes to specify property validation. For example: [NotNull] [StringLengthGreaterThen(0)] public string Username { …code } Thank u for your fast
support. Van:
Jehanzeb Musani [mailto:[EMAIL PROTECTED] As per
my experience with IBatis and as per my understanding of your problem, IBatis
calls the setter properties on an object only once when it is populating the
object with data. I have debugged the objects passed to IBatis many times and
the setter properties are called only once for an object population. The
behaviour as per my experience is that when IBatis creates an object via
reflection, all the member variables will be initialized to their default
values. You can override this by setting the values of the member variables to
your business-domain related sentinel values in default constructor. I hope
this helps. Can you provide the snippet of your code that is throwing the
exception?
From:
Arjen Smits [mailto:[EMAIL PROTECTED] I have an question concerning how ibatis fills the
object it maps its data to. I know it uses the properties of an object to set its
data. However in what sequence does it do this? Does it first initialises the
field by setting it to null? Or does it do some other form of initialisation
first before filling the object with the actual data? The reason I am asking is because currently I implemented
an sort of data integrity checking in the data object. However ibatis triggers the error mechanism when it
try’s to set the data in the object. For example: I got an Class User. This class has the String
Username property. In the set procedure of this property I check if the
value being used is not null and the string is longer then 0. If it is I throw
an specialised exception. So what happens now is that when I query the database
with an select and ibatis tries to fill the user object it throws this
specialised exception, indicating that the value being used is either null or
an empty string. After some debugging I found out it actually fills it with an
empty value first, afore putting in the “real” value. So it seems to initialise the object first with empty
values. Can I get confirmation of this behaviour ? | ||||||||||||
- Confirmation about how ibatis fills the objects it maps to... Arjen Smits
- RE: Confirmation about how ibatis fills the objects i... Jehanzeb Musani
- RE: Confirmation about how ibatis fills the objects i... Arjen Smits


