Thanks for answering.

If I don't use a nullValue it works as expected, but then, of course, I have
to use Integer instead of int.

I tried your solution with a resultMap attribute like this:

<resultMap id="Text-result" class="pim.domain.Text">
        <result property="id" column="textValue_tid_id" />
        <result property="languageId" column="textValue_tid_languageId"
nullValue="0" />
        <result property="value" column="textValue_tid_value" />
</resultMap>

<resultMap id="PropertyValue-result" class="pim.domain.PropertyValue">
        <result property="mediaIdValue" column="mediaIdValue" />
        <result property="id" column="id" />
        <result property="propertyTypeId" column="propertyTypeId" />
        <result property="text" column="textValue_tid_id"
resultMap="PropertyValue.Text-result"/>
</resultMap>


(I had to prefix the resultmap with the current namespace or else iBatis
didn't found it.)

--- The error occurred in sqlMaps/PropertyValue.xml.  
--- The error occurred while applying a result map.  
--- Check the PropertyValue.PropertyValue-result.  
--- The error happened while setting a property on the result object.  
--- Cause: com.ibatis.sqlmap.client.SqlMapException: Error instantiating
collection property for mapping 'text'.  Cause: java.lang.ClassCastException
Caused by: java.lang.ClassCastException

The row that seems to throw the exception is:

  try {
    c = (Collection) type.newInstance();   <----
  } catch (Exception e) {
    throw new SqlMapException("Error instantiating collection property for
mapping '" + mapping.getPropertyName() + "'.  Cause: " + e, e);
  }

It seems that iBatis is trying to cast the text object to a Collection? Is
this correct?

Reagards Okku


-----Original Message-----
From: Clinton Begin [mailto:[EMAIL PROTECTED] 
Sent: den 11 februari 2005 01:29
To: [email protected]
Subject: Re: NullValues and complex properties

What happens if you don't use a nullValue?

Also, you could make use of the new resultMap attribute to manage the
complex relationship:

<result property="text" column="textValue_tid_id" resultMap="Text-result"/>

And then map all of the text properties in that result map.

Cheeers,
Clinton

On Thu, 10 Feb 2005 13:48:07 +0100, Okku <[EMAIL PROTECTED]> wrote:
> We have a lot of tables with pk:s of type int.
> 
> Some of the references to these table id:s can be null, since it is
> convenient to have the same type we use int everywhere, and since no ids
in
> our database can have the value 0 we set the nullValue to 0.
> 
> This works well on classes without complex properties.
> 
> But for a resultmap like this:
> 
> <resultMap id="PropertyValue-result" class="pim.domain.PropertyValue">
>       <result property="mediaIdValue" column="mediaIdValue" />
>         <result property="id" column="id" />
>         <result property="propertyTypeId" column="propertyTypeId" />
>         <result property="text.id" column="textValue_tid_id" />
>         <result property="text.languageId"
column="textValue_tid_languageId"
> nullValue="0" />
>         <result property="text.value" column="textValue_tid_value" />
> </resultMap>
> 
> Where we use a complex type text and one of the properties languageId can
be
> null we get some strange behavior.
> 
> What we want is that the text property to be null if textValue_tid_id,
> textValue_tid_languageId and textValue_tid_value is null, but instead
iBatis
> creates a new text property object and sets the languageId to 0.
> 
> Is this the correct behavior?
> 
> Regards Okku Touronen
> 
>



Reply via email to