ibatis-user-cs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Arjen Smits" <ar...@ProPlanet.nl>
Subject RE: Confirmation about how ibatis fills the objects it maps to?
Date Thu, 10 Aug 2006 09:53:55 GMT
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:jehanzeb.musani@pdsr.com] 
Verzonden: donderdag 10 augustus 2006 11:35
Aan: user-cs@ibatis.apache.org
Onderwerp: RE: Confirmation about how ibatis fills the objects it maps
to?

 

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?

 

Jehanzeb Musani 
Software Developer 

PDSR Technologies FZ-LLC
Al Shatha Tower, 1406
Dubai Internet City
P.O. Box 502416
Dubai, UAE 

 

Tel:   +971  4   3692873
Fax:  +971  4   3688220
Mob: +971  50  2465392 

jehanzeb.musani@pdsr.com
http://www.pdsr.com
<https://mvp.support.microsoft.com/profile=662532B2-B798-4CEB-A102-01D94
55736B7> 

Legal Notice: This message may contain information which is confidential
and subject to legal privilege. If you are not the intended recipient,
you may not peruse, use, disseminate, distribute or copy this message.
If you have received this message in error, please notify the sender
immediately by email, facsimile or telephone and return and/or destroy
the original message. The views and/or opinions expressed within the
contents of his message are not necessarily those of PDSR Technologies
FZ-LLC or their affiliates. 

 

 

http://www.sharesense.com

 

 

 

  _____  

From: Arjen Smits [mailto:arjen@ProPlanet.nl] 
Sent: Thursday, August 10, 2006 10:48 AM
To: user-cs@ibatis.apache.org
Subject: Confirmation about how ibatis fills the objects it maps to?

 

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 ?

 


Mime
View raw message