You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@jackrabbit.apache.org by "Phukan, Anit" <An...@intuit.com> on 2009/10/06 19:38:43 UTC

Class Cast exception

Hi,

Could someone help me out with this?

I get this exception while trying to set property value for a node to an
object

 java.lang.ClassCastException: package.objectClassname cannot be cast to
javax.jcr.Value

In my code, I am trying to set the property value this way:

patientRecords.setProperty("PatientObject", (Value)
persistedObject.getObject());


where patientRecords is a node, and persistedObject is the object


Any suggestions would be appreciated.

Thanks
Anit 

Re: Class Cast exception

Posted by Alexander Klimetschek <ak...@day.com>.
On Tue, Oct 6, 2009 at 19:38, Phukan, Anit <An...@intuit.com> wrote:
> I get this exception while trying to set property value for a node to an
> object
>
>  java.lang.ClassCastException: package.objectClassname cannot be cast to
> javax.jcr.Value
>
> In my code, I am trying to set the property value this way:
>
> patientRecords.setProperty("PatientObject", (Value)
> persistedObject.getObject());
>
> where patientRecords is a node, and persistedObject is the object

You can't store an arbitrary object as property. It has to be a
javax.jcr.Value, ie. one of it's subclasses or simpler yet, using the
appropriate setProperty(String name, <type> value) method.

However, you can serialize your object and store it as a binary
property using setProperty(String,InputStream) in JCR 1.0 or
setProperty(String,Binary) in JCR 2.0.

Regards,
Alex

-- 
Alexander Klimetschek
alexander.klimetschek@day.com